我正在使用以下代码从SQL Server Express中分离我的数据库。请告知是否有问题。我收到一个错误。我的分离代码是否正确?
"Could not locate entry in sysdatabases for database 'EXEC master'. No entry found with that name. Make sure that the name is entered correctly."
我使用的代码是
Dim conn2 As New SqlConnection("Server=MyHomeServer\SQLExpress;Database=master;Trusted_Connection=False;User ID=sa;Password=abc123;")
Dim cmd2 As New SqlCommand("", conn2)
cmd2.CommandType = CommandType.StoredProcedure
cmd2.CommandText = "EXEC master.dbo.sp_detach_db @dbname = N'MyHomeDBTestPWD'"
conn2.Open()
cmd2.Connection = conn2
cmd2.ExecuteNonQuery()
非常感谢!您是否也可以像上面所做的那样为我写备份和恢复代码?我会非常感谢你。 – 2012-02-13 15:08:28
为了备份数据库,您需要使用'CommandType.Text'并自己指定SQL语句。这是MSDN上的备份页面。 http://msdn.microsoft.com/en-us/library/ms187510.aspx – 2012-02-13 15:10:34
相同的'RESTORE' http://msdn.microsoft.com/en-us/library/ms186858.aspx – 2012-02-13 15:11:24