【问题标题】:Where can I find a SQL Server Management Objects Collection for SQL Server Express?在哪里可以找到 SQL Server Express 的 SQL Server 管理对象集合?
【发布时间】:2019-07-31 01:44:23
【问题描述】:

我编写了一个从 Visual Studio 2017 运行时运行良好的应用程序,并使用以下库:

  • Microsoft.SqlServer.Management.Common
  • Microsoft.SqlServer.Management.Smo

但是当我尝试单独运行它时,我收到以下错误:

System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.SqlServer.ConnectionInfo,Version=14.100.0.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91”或其依赖项之一。该系统找不到指定的文件。文件名:'Microsoft.SqlServer.ConnectionInfo, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'

我追查到缺少 SQL Server 的 SQL Server 管理对象集合。

我需要知道如何解决此问题,或者是否可以为 SQL Server Express 解决此问题。我注意到这些包可用于购买的 SQL Server 版本的安装,但没有找到 Express。

【问题讨论】:

标签: c# sql-server sql-server-express smo


【解决方案1】:

你需要安装SQLSysClrTypes.msi

更新的链接 https://download.microsoft.com/download/1/3/0/13089488-91FC-4E22-AD68-5BE58BD5C014/ENU/x86/SQLSysClrTypes.msi

...也许重启你的 S.O

SQL = 结构化查询语言(后续只是拼音或 Ruby 的数据库工具)

旧链接 http://go.microsoft.com/fwlink/?LinkID=188392&clcid=0x409

当您说“已编译的可执行文件”时,您是否从 bin 文件夹中获取了 .exe、所有 .dll 和所有其他文件?请复制 bin 文件夹的全部内容。

【讨论】:

  • 感谢您的建议。安装并重新启动。仍然得到同样的错误。当我从 Visual Studio 2017 启动它时它可以工作,但是如果我使用该编译的可执行文件并自行启动它,我会收到该错误。我不知道为什么,因为它使用的是我的续集安装中的库。
  • 好的,也许您还有另一个常见问题。你在使用实体框架吗?当您说“已编译的可执行文件”时,您是否从 bin 文件夹中获取了 .exe、所有 .dll 和所有其他文件?
  • 使用 .NET Framework 4.6.1,不使用 Unity Framework。它只有一个可执行文件,没有 dll。
  • 请注意,我提到了“实体框架”而不是 Unity。您能否在代码中添加引发错误的行?
  • 太棒了!那是因为我很老了 :P .
【解决方案2】:

这就是函数。 DBServerTextBox.Text 是 @"localhost\SQLEXPRESS" DBDataTextBox.Text 是 DATA 目录的路径 标签刷新和线程睡眠,所以我可以在标签消息闪过之前看到它们。

private void AttachDatabaseToInstance()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = @"Data Source=" + DBServerTextBox.Text + @";Initial Catalog=master;;Integrated Security=True;Connect Timeout=30;User ID=dbadmin;Password=dbadmin";

        ServerConnection serverconn = new ServerConnection(con);
        Server s = new Server(serverconn);

        try
        {
            con.Close();
            InstallStatusLabel.Text = "Existing connections closed";
            InstallStatusLabel.Refresh();
            System.Threading.Thread.Sleep(3000);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        try
        {
            s.DetachDatabase("mydatabase", true);
            InstallStatusLabel.Text = "Detaching any existing mydatabase database";
            InstallStatusLabel.Refresh();
            System.Threading.Thread.Sleep(3000);
        }
        catch
        {
            MessageBox.Show("Could not find attached database");
        }
        try
        {
            s.AttachDatabase("mydatabase", new System.Collections.Specialized.StringCollection { DBDataTextBox.Text + @"\mydatabase.mdf", DBDataTextBox.Text + @"\mydatabase_log.ldf" }, AttachOptions.None);
            InstallStatusLabel.Text = "Attached mydatabase database";
            InstallStatusLabel.Refresh();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多