SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source =.; Initial Catalog = master; Integrated Security = True;";
con.Open();
string str = "USE master;" +
"EXEC sp_detach_db @dbname = N'PhoneBookDB'";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Detached", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
I get this error:
Cannot detach the database 'PhoneBookDB' because it is currently in use. Changed database context to 'master'.
What should I do?