I am using following code to detach my DB from SQL Server express. Please advise if there is something wrong with it. I am getting an error on it.
"Could not locate entry in sysdatabases for database 'EXEC master'. No entry found with that name. Make sure that the name is entered correctly."
The code I am using is
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()
You are assiging this the wrong way. You are allocating a proper SQL statement in the
CommandTextwhen you only need to add the Stored Procedure name. You will then need to add aParameterto yourSqlCommand.If you are alternatively wanting to execute your SQL statement, then you just need to change your
CommandTypetoCommandType.Text