主题:[原创]关于恢复的问题
请各位好心人帮忙看看:
Dim connect_string As String = "Data Source = SUN; Initial_ catalog = Master; user id=sa; persist security info = True"
Dim sql_command As New SqlClient.SqlCommand
Dim data_reader As SqlClient.SqlDataReader
Dim sql_connection As SqlClient.SqlConnection
sql_connection = New SqlClient.SqlConnection(connect_string)
'关闭用户进程,使数据库成功恢复
sql_command.CommandText = "Select spid From Master..sysprocesses where dbid=db_id('DBName')"
sql_command.Connection = sql_connection
sql_connection.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI"
sql_connection.Open()
data_reader = sql_command.ExecuteReader
If data_reader.Read() Then
sql_command.CommandText = "Kill @spid"
sql_command.Parameters.Add("@spid", data_reader.Item(0))
data_reader.Close()
sql_command.ExecuteNonQuery()
End If
'恢复数据库
sql_command.CommandText = "Restore database [DBName] From bf='C:\a.mdb' With Replace"
sql_command.ExecuteNonQuery() [color=FF0000] '到这里报错 [/color]
MsgBox("备份完成!", MsgBoxStyle.OKOnly)
End Sub
[em7][em7][em7][em7]
Dim connect_string As String = "Data Source = SUN; Initial_ catalog = Master; user id=sa; persist security info = True"
Dim sql_command As New SqlClient.SqlCommand
Dim data_reader As SqlClient.SqlDataReader
Dim sql_connection As SqlClient.SqlConnection
sql_connection = New SqlClient.SqlConnection(connect_string)
'关闭用户进程,使数据库成功恢复
sql_command.CommandText = "Select spid From Master..sysprocesses where dbid=db_id('DBName')"
sql_command.Connection = sql_connection
sql_connection.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI"
sql_connection.Open()
data_reader = sql_command.ExecuteReader
If data_reader.Read() Then
sql_command.CommandText = "Kill @spid"
sql_command.Parameters.Add("@spid", data_reader.Item(0))
data_reader.Close()
sql_command.ExecuteNonQuery()
End If
'恢复数据库
sql_command.CommandText = "Restore database [DBName] From bf='C:\a.mdb' With Replace"
sql_command.ExecuteNonQuery() [color=FF0000] '到这里报错 [/color]
MsgBox("备份完成!", MsgBoxStyle.OKOnly)
End Sub
[em7][em7][em7][em7]