请大家帮帮我啊,真得很急啊~~
我做的还原是全部用存储过程实现的
要先在数据库(master)里面建杀进程的存储过程KILLSPID和还原的储存过程
dim cn as new sqlconnect("data source=(local);database=数据库名称;integrated security=true")
cn.Open()
Dim cmdatabase As New SqlCommand
cmdatabase.connection = cn
cmdatabase.commandtext = "sp_helpdb"
cmdatabase.commandtype = CommandType.StoredProcedure
Dim Kill As New SqlCommand
Kill.connection = cn
Kill.commandtext = "[killspid]"
Kill.commandtype = CommandType.StoredProcedure
Kill.Parameters.Add("@return_value", SqlDbType.Int, 4)
Kill.parameters("@return_value").direction = ParameterDirection.ReturnValue
Kill.parameters.add("@dbname", SqlDbType.VarChar, 20)
cn.close()
接下来是在按钮的单击事件下
dim result as windows.forms.dialogresult
openfiledialog.filter="bak格式(*.bak)/*.bak"
openfiledialog.title="打开文件"
result=openfiledialog.showdialog()
if result=dialogresult.ok and len(openfiledialog.filename)>0 then
restoredisk=openfiledialog.filename
else
exit sub
end if
cmrestore.parameters(1).value=restoredb
cmrestore.parameters(2).value=restoredisk
kill.parameters(1).value=restoredb
'进行还原数据库
try
cn.open()
kill.exexutenonquery()
cmrestore.executenonquery()
catch ex as exception
label1.text=ex.tostring()
end try
cn.close