无法从程序集'System.Data,Version = 4.0.0.0加载类型'Microsoft.SqlServer.Server.SqlContext' [英] Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0
问题描述
在尝试还原sqlserver 2012中的数据库时遇到了问题.
I have facing a problem while i am trying to restore the Data base in sqlserver 2012 .
我的项目配置:
ASP.Net core 2.0,Vs2017 Preview2,c#
我已使用nuget软件包安装了 Microsoft.SqlServer.Scripting ,然后我尝试使用以下代码还原数据库
i have installed Microsoft.SqlServer.Scripting using nuget package , then i tried to restore data base using below code
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();
}
错误是:
无法从中加载类型'Microsoft.SqlServer.Server.SqlContext'程序集'System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'.
Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我错过了什么吗?你能请任何人帮我这个忙吗?
Did i miss anything? can you please any body help me out this .
推荐答案
我今天遇到了同样的问题.我通过引用 Microsoft.SqlServer.SqlManagementObjects 解决了这个问题.
I had the same problem today. I solved it by referencing Microsoft.SqlServer.SqlManagementObjects.
这篇关于无法从程序集'System.Data,Version = 4.0.0.0加载类型'Microsoft.SqlServer.Server.SqlContext'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!