Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..
When i am trying to take the backup of my database from sqlserver 2005 using c# ,it gives the error as "Failed to connect to server .\sqlexpress.". I have used the code in DBBackup_click event is :

Backup sqlBackup = new Backup();
       sqlBackup.Action = BackupActionType.Database;
       sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
       sqlBackup.BackupSetName = "Archive";
       sqlBackup.Database = databaseName;
       BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
       //SqlConnection sqlCon = new SqlConnection("server=192.168.2.209;database=charity;uid=sa;pwd=pass");
       //ServerConnection connection = new ServerConnection(sqlCon);
       ServerConnection connection = new ServerConnection(serverName, userName, password);
       Server sqlServer = new Server(connection);
       Database db = sqlServer.Databases[databaseName];
       sqlBackup.Initialize = true;
       sqlBackup.Checksum = true;
       sqlBackup.ContinueAfterError = true;

       sqlBackup.Devices.Add(deviceItem);
       sqlBackup.Incremental = false;

       sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
       sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;

       sqlBackup.FormatMedia = false;
       sqlBackup.SqlBackup(sqlServer);  /* Here, It throws the error */



can anyone tell me , how to solve this error?
Posted
Updated 27-Jul-11 4:44am
v3

Failed to connect sounds to me like your connection string is broken.
 
Share this answer
 
Comments
Tech Code Freak 29-Jul-11 10:29am    
Same opinion..........My 5!
Read this[^]
 
Share this answer
 

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