- C# code
protected void bfbtn_Click(object sender, ImageClickEventArgs e) { SQLDMO.Backup oBackup = new SQLDMO.BackupClass(); SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass(); try { string filename = DateTime.Now.ToString() + ".bak"; oSQLServer.LoginSecure = false; oSQLServer.Connect("local", "sa", "daili"); oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database; oBackup.Database = "medicine"; oBackup.Files = @"E:\88789\医学\" + filename; oBackup.BackupSetName = "medicine"; oBackup.BackupSetDescription = "数据库备份"; oBackup.Initialize = true; oBackup.SQLBackup(oSQLServer); if (dataBaseDB.AddDataBase(filename)) { Response.Write(dataBaseDB.clew("数据库备份成功!", "/admin/database/databaseList.aspx")); } else { Response.Write(dataBaseDB.clew("数据库备份失败!", "/admin/database/databaseList.aspx")); } } catch (Exception ex) { throw ex; } finally { oSQLServer.DisConnect(); } }
出现错误:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
源错误:
行 66: catch (Exception ex)
行 67: {
行 68: throw ex;
行 69: }
行 70: finally
------解决方案--------------------------------------------------------
解决了,不能只回一个"解决了"啊!
得说说怎么解决的?
神马地方出的问题啊?给大家分享一下呢!
ps:是不是sql2005 Before Compact的问题?
------解决方案--------------------------------------------------------
http://topic.csdn.net/u/20110527/11/94f5b568-511d-46c0-9696-4497f1c865b4
使用sqldmo备份还原数据库参考