【问题标题】:Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0无法从程序集“System.Data,版本=4.0.0.0”加载类型“Microsoft.SqlServer.Server.SqlContext”
【发布时间】:2018-01-14 22:13:56
【问题描述】:

我在尝试恢复 sqlserver 2012 中的数据库时遇到问题。

我的项目配置:

ASP.Net 核心 2.0, VS2017 Preview2, c#

我已经使用 nuget 包安装了 Microsoft.SqlServer.Scripting,然后我尝试使用以下代码恢复数据库

try
{
    string DatabaseName = "TestDB";
    String ConnectionString = "Data Source=(local);Initial Catalog= " + DatabaseName + ";Integrated Security=SSPI;";
    SqlConnection sqlConnection = new SqlConnection(ConnectionString);
    // Error on the line below
    Microsoft.SqlServer.Management.Common.ServerConnection conn = new Microsoft.SqlServer.Management.Common.ServerConnection(sqlConnection);
    Server srv = new Server(conn);
    Console.WriteLine(srv.Information.Version);
}
catch (Exception ex)
{
    string exepe = ex.Message.ToString();
}

错误是:

无法从 程序集'System.Data,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089'。

我错过了什么吗?你能请任何人帮我解决这个问题吗?

【问题讨论】:

  • .NET Core 可能不存在(packagesearch 和 github corefx 上都不存在),您必须改为以 .NET Framework 为目标
  • 您好 Tseng 感谢您的回复,是的,我尝试了 .Net Framework 也给出了同样的错误。我尝试在那里使用 Windows 应用程序。

标签: c# asp.net-core


【解决方案1】:

我今天也遇到了同样的问题。我通过引用Microsoft.SqlServer.SqlManagementObjects解决了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    相关资源
    最近更新 更多