[此贴子已经被作者于2006-11-21 11:28:15编辑过]
有一种杀死进程的,不过我没试,你参考一下:
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;
iColDbName = i;
}
else if (strName.ToUpper().Trim() == "xrfdc")
{
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);
}
svr.LoginSecure = false;//++