试着把改成这样看看:把连接的数据库改为master
Private Sub myRebak() Dim cn As New ADODB.Connection
With cn
.ConnectionTimeout = 60
.CursorLocation = adUseServer
.Mode = adModeShareExclusive
.Open "Provider=SQLOLEDB;Server=" + ServerName + ";Database=master;Uid=" + ServerID + ";Pwd=" + ServerPassword + ";"
'.Execute "sp_dboption myinvoice,'single user','true'"
.Execute "alter database myinvoice set SINGLE_USER"
.Execute "restore database myinvoice from disk='" + App.Path + "\" + Combo1.Text + ".dat'"
'.Execute "alter database myinvoice set MULTI_USER"
'错误提示:因为数据库正在使用,所以未能获得对数据库的排他访问权
End With
End Sub
Private Sub myRebak() Dim cn As New ADODB.Connection
With cn
.ConnectionTimeout = 60
.CursorLocation = adUseServer
.Mode = adModeShareExclusive
.Open "Provider=SQLOLEDB;Server=" + ServerName + ";Database=master;Uid=" + ServerID + ";Pwd=" + ServerPassword + ";"
'.Execute "sp_dboption myinvoice,'single user','true'"
.Execute "alter database myinvoice set SINGLE_USER"
.Execute "restore database myinvoice from disk='" + App.Path + "\" + Combo1.Text + ".dat'"
'.Execute "alter database myinvoice set MULTI_USER"
'错误提示:因为数据库正在使用,所以未能获得对数据库的排他访问权
End With
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货