This is just another SQL C# articles which let you learn how to check for a database existence on SQL Server.
All you have to do query names in sys.databases table and make sure it is available to use. You can create a function for the purpose.
public static bool IsDBExist(string server, string db) { List<string> list = new List<string>(); // Open connection to the database string conString = null; ; conString = "server=" + server + ";uid=sa;"; bool has = false; try { using (SqlConnection con = new SqlConnection(conString)) { if (con.State == ConnectionState.Open) con.Close(); con.Open(); // Set up a command with the given query and associate // this with the current connection. using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases where name='" + db + "'", con)) { using (IDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { list.Add(dr[0].ToString()); } if (list.Count > 0) has = true; } } con.Close(); } } catch (Exception er) { MessageBox.Show(er.Message.ToString()); } return has; }