使用 SMO 运行 SQL 安装脚本。 需要替代解决方案
我有一个使用 Microsoft Sql 管理对象 (SMO) dll 的 Web 应用程序。 我想知道如何为远程计算机重新分发库。
据我了解,它们附带 SQL Server 或 Sql Express - 不在远程(共享)网络服务器上。 要求主机安装它们可能是不可能的,那么是否可以动态加载它们?
请参阅下面的错误 -
无法加载文件或程序集“Microsoft.SqlServer.Smo,Version=9.0.242.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91”或其依赖项之一。 该系统找不到指定的文件。
或者,如果任何人都可以为下面的代码片段提供解决方法,这也会很有用。 script 变量是一个已读到底的 SQL 安装脚本。 这样做的好处是从 SQL 输出每个执行字符串。 我当然可以将其全部执行在一个块中,但这不会向用户逐行提供视觉反馈,表明 SQL 执行正常。
是否有一个存储过程可以执行此类操作? 或者在没有完全权限的情况下执行安装脚本的替代方法。
Dim connection As New SqlConnection(Me.ConnectionString)
connection.Open()
connection.Close()
Dim server As New Server(New ServerConnection(connection))
server.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteAndCaptureSql
Dim commands As StringCollection = server.ConnectionContext.CapturedSql.Text
server.ConnectionContext.ExecuteNonQuery(script, ExecutionTypes.ContinueOnError)
Dim s As String
For Each s In server.ConnectionContext.CapturedSql.Text
AppendMessages(s)
Next
I've got a web application that uses Microsoft Sql Management Objects (SMO) dll's. I'm wondering how I go about redistributing the libraries for a remote machine.
As I understand it, these come with SQL server or Sql express - which isn't on the remote (shared) webserver. Asking the host to install them, is probably out of the question, so is it possible to dynamically load them?
See below error-
Could not load file or assembly 'Microsoft.SqlServer.Smo, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
Alternatively, if anyone can provide a workaround for the below snippet that would also be useful. The script variable is a SQL install script which has been read to the end. The nice thing about this is the outputting of each of the execute strings from SQL. I could of course just execute it all in one chunk, but that provides no visual feedback to the user line by line, that the sql is executing ok.
Is there a stored procedure that could perform this sort of thing? Or an alternative way to execute an install script without full permissions.
Dim connection As New SqlConnection(Me.ConnectionString)
connection.Open()
connection.Close()
Dim server As New Server(New ServerConnection(connection))
server.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteAndCaptureSql
Dim commands As StringCollection = server.ConnectionContext.CapturedSql.Text
server.ConnectionContext.ExecuteNonQuery(script, ExecutionTypes.ContinueOnError)
Dim s As String
For Each s In server.ConnectionContext.CapturedSql.Text
AppendMessages(s)
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://www.mattberther.com /2005/04/11/executing-a-sql-script-using-adonet/
来自
http://coolthingoftheday.blogspot.com/2006/11/execute-t-sql-scripts-with-gos.html
就是我正在寻找的并做到了。
http://www.mattberther.com/2005/04/11/executing-a-sql-script-using-adonet/
from
http://coolthingoftheday.blogspot.com/2006/11/execute-t-sql-scripts-with-gos.html
Was what I was looking for, and did the trick.
您可以尝试使用sql server附带的sqlcmd实用程序
you can try using sqlcmd utilty that comes with sql server
不,您不能动态加载它们,并且没有权限,您不能安装它们。 抱歉,那里没有骰子。
No, you can't dynamically load them, and no, you can't install them without permissions. Sorry about that, but no dice there.