マスターデータベースは既に存在するため、復元する必要はありません。 ADO.NETプロバイダAPIを使用してデータベースを削除することができます。
using(SqlConnection cn = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=master;Integrated Security=True"))
{
using(SqlCommand cmd = new SqlCommand("drop database yourdbName", cn))
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}
EDIT:
using(SqlCommand cmd = new SqlCommand("drop database [07-02-2012]", cn))
{..}
あなたは、接続文字列を変更し、DataContext.DeleteDatabase()
メソッドを使用する必要があります。
string cnstr = @"Data Source=.\SQLEXPRESS;AttachDbFileName=c:\file.mdf;Integrated Security=true";
MyDbContext dx = new MyDbContext(cnstr);
if (dx.DatabaseExists())
{
dx.DeleteDatabase();
}
希望これは..あなたを助ける http://stackoverflow.com/questions/7775409/database-already-exist-choose-a-different-name-using-createdatabase私はそれを見た –
しかし、それを行う方法はありません.. – remi
あなたはSQL Serverの管理スタジオを持っていますか? –