string sBackup = @"restore DATABASE " + sqlConnection.Database + " from DISK = '" + this.txtRestoreFileName.Text + "'";
sqlConnection.Open();
sqlConnection.ChangeDataBase("master");//加上这句试试
SqlCommand myCommand = new SqlCommand(sBackup, sqlConnection);
sqlConnection.Open();
sqlConnection.ChangeDataBase("master");//加上这句试试
SqlCommand myCommand = new SqlCommand(sBackup, sqlConnection);
2. restart ms sql server service.
然后启动一下,就好了
connectstring里面要连master数据库
我在sql analyse的master下运行也一样报错.
这是为什么?
你们都是怎么做的?是不是还要改什么东西?
Set conRestore = New ADODB.Connection
conRestore.ConnectionString = strConnectString
conRestore.CursorLocation = adUseClient
conRestore.Open
conRestore.DefaultDatabase = "Master" '此句必须要加
strRestore = "restore database EIMS from disk=" & "'" & Trim(txtDir.Text) & "'" & " with REPLACE"
conRestore.BeginTrans
conRestore.Execute strRestore
err.Number = 0
If err.Number = 0 Then
conRestore.CommitTrans
MsgBox "数据恢复成功!", vbInformation, "提示"
Else
conRestore.RollbackTrans
MsgBox "数据恢复失败!请检查数据库是否正在打开!", vbCritical, "提示"
End If
conRestore.Close
Set conRestore = Nothing
declare @spt table (spid int)
declare @spid int , @sql varchar(255)insert into @spt select spid from master.dbo.sysprocesses where dbid = db_id('GSPMgr') and spid <> @@spiddeclare sp_cur cursor for
select spid from @spt
open sp_curfetch next from sp_cur into @spid
set @sql = 'kill '+ cast ( @spid as varchar(8) )
exec (@sql)while @@FETCH_STATUS = 0
begin
fetch next from sp_cur into @spid
set @sql = 'kill '+ cast ( @spid as varchar(8) )
exec (@sql)
endclose sp_cur
deallocate sp_cur
go
然后再备份就可以了.