4

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 .

2
  • 1
    It's likely not there (neither on packagesearch nor on github corefx) for .NET Core and you have to target .NET Framework instead Commented Aug 7, 2017 at 16:00
  • Hello Tseng thanks for your reply , yeah i tried .Net Framework also i gives same error . I tried with windows application there it works. Commented Aug 7, 2017 at 16:18

1 Answer 1

2

I had the same problem today. I solved it by referencing Microsoft.SqlServer.SqlManagementObjects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.