【发布时间】:2018-07-30 10:45:51
【问题描述】:
我试图在 vb.net 中恢复我的备份数据库,但我遇到了这个问题,这是什么问题?
这是我正在使用的代码。
Private Sub btnRestore_Click(sender As Object, e As EventArgs) Handles btnRestore.Click
Try
Dim con2 As New SqlConnection
Dim cmd2 As New SqlCommand
Dim Filename2 As String
Dim strQuery2 As String
Dim database2 As String
Dim get_servername2 As String
'get value in selected database name dropdown menu in combo box
database2 = cmbdatabase.Text
get_servername2 = cmbservername.Text.Trim 'selecting servername
Dim opendlg As New OpenFileDialog
Dim constr2 As String
constr2 = "Data Source=" & get_servername2 & ";Initial Catalog=master; Integrated Security= True "
If opendlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.Cursor = Cursors.WaitCursor
con2 = New SqlConnection(constr2)
con2.Open()
Filename2 = opendlg.FileName
strQuery2 = " Restore database " & database2 & " from disk = '" & Filename2 & "'"
'exe command
Try
cmd2 = New SqlCommand(strQuery2, con2)
cmd2.ExecuteNonQuery()
MessageBox.Show("Database " & database2 & " has been restored successfully. ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
con2.Close()
Me.Cursor = Cursors.Default
Catch ex As Exception
Me.Cursor = Cursors.Default
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End If
Catch ex As Exception
Me.Cursor = Cursors.Default
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
【问题讨论】:
-
您应该在此处接受答案并创建一个新问题,而不是更改(已回答)问题中的错误消息。
标签: vb.net sql-server-2012 database-restore