0
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")
'Dim strDatabasePath As String = My.Computer.FileSystem.CombinePath(Application.UserAppDataPath, "LIC.mdf")
'Dim strdbLogPath As String = My.Computer.FileSystem.CombinePath(Application.UserAppDataPath, "LIC_log.ldf")
MsgBox(Application.UserAppDataPath)
' 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)
MsgBox(srv.ToString)
If srv.Databases.Contains(strDatabasePath) Then
MsgBox("In If")
If con.State = ConnectionState.Open Then
MsgBox(con.State)
con.Close()
End If
MsgBox(con.State & " Is It True?")
srv.KillAllProcesses(My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC.mdf"))
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 Exception
MessageBox.Show("Error Occured : " & ex.Message)
End Try
End Sub
我使用给定的代码复制我的数据库文件设置...它的工作原理是在调试模式下的魅力,但只要我 创建一个安装
。 ..它停止工作...错误是“数据库分离失败” ... 我试图检查代码行一行,发现代码
不进入IF块.. 。我不知道为什么...我可以得到一些帮助吗?
代码停止工作后,我创建使用发布向导
发生了什么stackoverflow?没有一个答复? – user1150440 2012-01-15 15:04:42