Click here to Skip to main content
15,847,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all

I want to backup of my database server with c sharp. I saw a method in google. and using this method now its create a error "failed to connect to server VS ".
  private void btnBackup_Click(object sender, EventArgs e)
//            Back();

        public void BackupDatabase(String databaseName, String userName,String password, String serverName, String destinationPath)
            Backup sqlBackup = new Backup();
            sqlBackup.Action = BackupActionType.Database;
            sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
            sqlBackup.BackupSetName = "Archive";
            sqlBackup.Database = "RPSJDB";
            BackupDeviceItem deviceItem = new BackupDeviceItem("c:\\RPSJDB\\mk.mdf", DeviceType.File);
            ServerConnection connection = new ServerConnection("VS", "Sa", "manish");
            Server sqlServer = new Server(connection);
            Database db = sqlServer.Databases["RPSJDB"];
            sqlBackup.Initialize = true;
            sqlBackup.Checksum = true;
            sqlBackup.ContinueAfterError = true;
            sqlBackup.Incremental = false;
            sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
            sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
            sqlBackup.FormatMedia = false;
Updated 28-Oct-13 20:50pm
Madhu Nair 29-Oct-13 2:08am    
Using the same connection string, are you able to connect to the server using SQL Management Studio?
Manish Arya 29-Oct-13 2:12am    
string connstr = @"Server=\MSSQL;Initial Catalog=RPSJDB; Uid=Sa; Pwd=manish; Max Pool Size=100";

yes I m connected with sql management studio. I can insert,delete everything.

1 solution

try changing the below line from -
ServerConnection connection = new ServerConnection("VS", "Sa", "manish");

To -

ServerConnection connection = new ServerConnection("\MSSQL", "Sa", "manish");


Refer This
Share this answer
Manish Arya 29-Oct-13 2:33am    
same problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900