Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0

Viewed 3129

I have facing a problem while i am trying to restore the Data base in sqlserver 2012 .

My project configuration :

ASP.Net core 2.0, Vs2017 Preview2, c#

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();
}

Error is :

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 .

1 Answers
Related