-2
錯誤:「服務器'MONO-PC \ SQLEXPRESS'的分離數據庫失敗。」服務器'MONO-PC SQLEXPRESS'的分離數據庫失敗
Public Sub bk()
Try
Dim strDatabasePath As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC.mdf")
Dim strdbLogPath As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC_log.ldf")
' DB.Connection can be any valid SQLConnection which you might already be using in your application
Dim con As New SqlClient.SqlConnection(LIC.My.Settings.LICConnectionString)
Dim srvCon As New ServerConnection(con)
Dim srv As Server = New Server(srvCon)
If srv.Databases.Contains(strDatabasePath) Then
If Not con.State = ConnectionState.Closed Then
con.Close()
End If
srv.DetachDatabase(strDatabasePath, True)
My.Computer.FileSystem.CopyFile(strDatabasePath, "c:\backup\LIC.mdf", True)
My.Computer.FileSystem.CopyFile(strdbLogPath, "c:\backup\LIC_log.ldf", True)
MessageBox.Show("Backup taken successfully")
End If
srvCon.Disconnect()
con.Open()
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
End Sub
爲什麼它失敗??任何幫助讚賞。
你能至少發佈錯誤/異常,你得到? – 2012-01-15 06:59:03
「服務器'MONO-PC \ SQLEXPRESS'的分離數據庫失敗。」這是我執行這行時得到的'srv.DetachDatabase(strDatabasePath,True)' – 2012-01-15 07:02:13