używam tego kodu, aby usunąć bazę danych do C#bazie spada SQL Server za pośrednictwem C#
Int32 result = 0;
try
{
String Connectionstring = CCMMUtility.CreateConnectionString(false, txt_DbDataSource.Text, "master", "sa", "happytimes", 1000);
SqlConnection con = new SqlConnection();
con.ConnectionString = Connectionstring;
String sqlCommandText = "DROP DATABASE [" + DbName + "]";
if (con.State == ConnectionState.Closed)
{
con.Open();
SqlConnection.ClearPool(con);
con.ChangeDatabase("master");
SqlCommand sqlCommand = new SqlCommand(sqlCommandText, con);
sqlCommand.ExecuteNonQuery();
}
else
{
con.ChangeDatabase("master");
SqlCommand sqlCommand = new SqlCommand(sqlCommandText, con);
sqlCommand.ExecuteNonQuery();
}
con.Close();
con.Dispose();
result = 1;
}
catch (Exception ex)
{
result = 0;
}
return result;
Ale pojawia się błąd
Baza aktualnie w użyciu
Czy ktoś może pomóc?
http://knownexception.blogspot.com/2010/05/mssql-cannot-drop-database-because-it.html –
Która linia daje wyjątek? –
Możliwy duplikat http://stackoverflow.com/questions/5170429/deleting-database-from-c-sharp –