Home > database >  Microsoft.SqlServer.Management.Common.ServerConnection constructor does not accept SqlConnection, bu
Microsoft.SqlServer.Management.Common.ServerConnection constructor does not accept SqlConnection, bu

Time:10-20

so the problems is that i receive an error when passing SqlConnection class to ServerConnection class. the error says:
Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'System.Data.SqlClient.SqlConnection' to 'Microsoft.SqlServer.Management.Common.IRenewableToken'
but here it says it can, and in the visual studio says it has that overload but it wont accept it and wont build the project.

I should also mention that when i try to assign the object directly, Visual Studio gets unresponsive and its framerate is like 0.5/s.like this:
ServerConnection servConn = new ServerConnection(){SqlConnectionObject = conn};

this is the whole code block:

SaveFileDialog sfd = new SaveFileDialog();
        string stringCon = @"DefaultConnection";
        sfd.Filter = "Database backup files (*.bak)|*.bak";
        sfd.Title = "Create Database Backup";
        sfd.FileName = DateTime.Today.ToString("ddMMMyyyy")   ".bak";
        if (sfd.ShowDialog() == true)
        {
            SqlConnectionInfo conn = new SqlConnectionInfo(stringCon);
           
                ServerConnection servConn = new ServerConnection();
            SqlConnection.ClearAllPools();
            conn.Open();
            servConn.Connect();
            try
            {
                Server serverdb = new Server(servConn);
                Backup backupdb = new Backup() { Action = BackupActionType.Database, Database = "whdb" };
                backupdb.Devices.AddDevice(sfd.FileName, DeviceType.File);
                backupdb.Initialize = true;
                backupdb.Incremental = false;
                backupdb.SqlBackupAsync(serverdb);
                conn.Close();
                Storyboard sb = Resources["sbHideAnimation"] as Storyboard;
                StatusLable.Content = @"اطلاعات صادر شد.";
                sb.Begin(StatusLable);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

CodePudding user response:

There are two different sets of classes for SqlClient.

There are two components

System.Data.SqlClient
Microsoft.Data.SqlClient

So you have to make sure to use the correct using statement.

  • Related