I use the code below to detach a Database, but if the database does not
exist, it will thow exception.
How can I determinate if the Database exist before detach it?
***********************************************************************
string sConnection = "Data Source=......";
string sCmdDetach="sp_detach_db 'Health'";
SqlConnection cnn = new SqlConnection(sConnection);
cnn.Open();
SqlCommand cmd= new SqlCommand(sCmdDetach, cnn);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cnn.Close();
}