还原数据库时发现,在进入这个界面时调用数据库验证用户后,然后还原就说正在使用,不能还原,就算close了也还是不行,高手指导一下吧,还有没有其他方法啊!!!!!!
SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect("localhost", "sa", "");
oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
oRestore.Database = "a";
oRestore.Files =@"c:\windows\"+"11.bck"; oRestore.FileNumber = 1;
oRestore.ReplaceDatabase = true;
oRestore.SQLRestore(oSQLServer);
MessageBox.Show("成功"); 这个方法在没调用数据库时就可以,先调用数据库就不行了,close也关不到

解决方案 »

  1.   

    把数据库连接conn
    conn.Close();
    conn.Dispose();
    GC.Collect();
    之后试试,看看行吗
      

  2.   

    数据库的关闭
    conn.Close();
    conn.Dispose();
    都试了,好像还是不行
    conn.state显示的还是open
      

  3.   

    ft63(ft) 
    GC.Collect();是什么???
      

  4.   

    靠!!!
    小case!!!!!
      

  5.   

    自己up一下,close()没有真正的关闭数据库连接啊!!
    http://community.csdn.net/Expert/topic/3480/3480409.xml?temp=.8576624 
    有没有其他方法呢?
      

  6.   

    晕,这不是SqlConnection的数据库关闭没有作用,这和ADO.NET没有关系,我可以给你我的原代码,给我发邮件吧 [email protected]
      

  7.   

    谢谢 lilionline(一滴水的海)
    问题我解决了,是用杀死所有用户进程解决的
    http://community.csdn.net/Expert/topic/3167/3167207.xml?temp=.6428949
      

  8.   

    不过我看了很多帖子都说close没有真正的断开,他们还在连接池里,杀死进程是可行的
      

  9.   

    用SQLSERVER.enumprocess得到连接到数据库的所有进程,然后用killprocess方法把这些进程全关闭就行!
      

  10.   

    SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass() ; 
    try 

    //服务器名,数据库用户名,数据库用户名密码
    svr.Connect("localhost","sa","") ;

    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 ; 

    //杀死使用strDbName数据库的进程
    for(int i=1;i<=qr.Rows;i++) 

    int lPID = qr.GetColumnLong(i,iColPIDNum) ; 
    string strDBName = qr.GetColumnString(i,iColDbName) ; 
    if (strDBName.ToUpper() == "fingerPrint".ToUpper()) 
    {
    svr.KillProcess(lPID) ; 
    }

                   
      

  11.   

    谢谢unique327(飞扬)和 ChineseeBoy(RMB) 
    你们和我的思路差不多
    谢谢ChineseeBoy(RMB)给出代码