使用 SMO 运行 SQL 安装脚本。 需要替代解决方案

发布于 2024-07-14 23:29:26 字数 1187 浏览 8 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女净妖师 2024-07-21 23:29:26

您可以尝试使用sql server附带的sqlcmd实用程序

you can try using sqlcmd utilty that comes with sql server

待天淡蓝洁白时 2024-07-21 23:29:26

不,您不能动态加载它们,并且没有权限,您不能安装它们。 抱歉,那里没有骰子。

No, you can't dynamically load them, and no, you can't install them without permissions. Sorry about that, but no dice there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文