本文介绍了sql备份中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 亲爱的所有 我想用c sharp备份我的数据库服务器。我在google中看到了一种方法。现在使用此方法会产生错误无法连接到服务器VS。 private void btnBackup_Click( object sender,EventArgs e) { BackupDatabase( RPSJDB, Sa, manish, VS, C:\\RPSJ.mdf); // 返回(); } public void BackupDatabase(字符串 databaseName,字符串 userName,字符串密码,字符串 serverName,字符串 destinationPath) {备份sqlBackup = new Backup(); sqlBackup.Action = BackupActionType.Database; sqlBackup.BackupSetDescription = ArchiveDataBase: + DateTime.Now.ToShortDateString(); sqlBackup.BackupSetName = 存档; sqlBackup.Database = RPSJDB; BackupDeviceItem deviceItem = new BackupDeviceItem( c :\\ RPSJDB \\mk.mdf,DeviceType.File); ServerConnection connection = new ServerConnection( VS , Sa, manish); Server sqlServer = new 服务器(连接); 数据库db = sqlServer.Databases [ RPSJDB]; 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); } 解决方案 尝试更改以下行 - ServerConnection connection = new ServerConnection( VS, Sa, manish); To - ServerConnection连接=新的ServerConnection(192.168.10.2 \ MSSQL,Sa,manish); b $ b或 参考此 Dear allI 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) { BackupDatabase("RPSJDB","Sa","manish","VS","c:\\RPSJ.mdf");// 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.Devices.Add(deviceItem); sqlBackup.Incremental = false; sqlBackup.ExpirationDate = DateTime.Now.AddDays(3); sqlBackup.LogTruncation = BackupTruncateLogType.Truncate; sqlBackup.FormatMedia = false; sqlBackup.SqlBackup(sqlServer); } 解决方案 try changing the below line from -ServerConnection connection = new ServerConnection("VS", "Sa", "manish");To -ServerConnection connection = new ServerConnection("192.168.10.2\MSSQL", "Sa", "manish");OR Refer This 这篇关于sql备份中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 08:35