C# 데이터베이스 복원 작업

7903 단어
C# 데이터베이스 복원 작업 /// /// /// /// /// /// /// Log /// /// /// /// /// public static bool RestoreDB(string strDbName, string strFileName,string dbDataName,string dbLogName,string dbPath, string serverName, string userName, string password) { SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass(); try { svr.Connect(serverName, userName, password); SQLDMO.QueryResults qr = svr.EnumProcesses(-1); int iColPIDNum = -1; int iColDbName = -1; for (int i = 1; i <= qr.Columns; i++) { string strName = qr.get_ColumnName(i); if (strName.ToUpper().Trim() == "SPID") { iColPIDNum = i; } else if (strName.ToUpper().Trim() == "DBNAME") { iColDbName = i; } if (iColPIDNum != -1 && iColDbName != -1) break; } for (int i = 1; i <= qr.Rows; i++) { int lPID = qr.GetColumnLong(i, iColPIDNum); string strDBName = qr.GetColumnString(i, iColDbName); if (strDBName.ToUpper() == strDbName.ToUpper()) svr.KillProcess(lPID); } SQLDMO.Restore res = new SQLDMO.RestoreClass(); res.Action = 0; res.Files = strFileName; res.RelocateFiles = @"[" + dbDataName + "],[" + System.IO.Path.Combine(dbPath, strDbName + "_Data.mdf") + "],[" + dbLogName + "],[" + System.IO.Path.Combine(dbPath, strDbName + "_log.ldf") + "]"; res.Database = strDbName; res.ReplaceDatabase = true; res.SQLRestore(svr); return true; } catch (Exception err) { throw (new Exception(" , !" + err.Message)); } finally { svr.DisConnect(); } }
COM의 SQLDMO를 참조해야 합니다.
posted on
2013-04-17 22:22 폭풍 독주
...) 설명(
...) 모음 편집
다음으로 전송:https://www.cnblogs.com/Shadow3627/archive/2013/04/17/3027252.html

좋은 웹페이지 즐겨찾기