本文整理汇总了C#中DataContext.DeleteDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.DeleteDatabase方法的具体用法?C# DataContext.DeleteDatabase怎么用?C# DataContext.DeleteDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.DeleteDatabase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReCreateDatabaseFromAttributeMapping
protected void ReCreateDatabaseFromAttributeMapping(DataContext ctx)
{
bool success = false;
bool retry = false;
int retries = 0;
do
{
try
{
using (ctx)
{
CloseAllOpenConnections(ctx);
ctx.Log = new StringWriter();
if (ctx.DatabaseExists())
{
//drop all connections by disabling multi-user (and immediatly abort all current transactions)
ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
ctx.DeleteDatabase();
}
try
{
ctx.CreateDatabase();
}
catch (Exception e)
{
Debug.WriteLine(e);
Debug.WriteLine(ctx.Log);
throw;
}
//re-enable multi-user (again)
ctx.ExecuteCommand("ALTER DATABASE " + _databaseName + " SET MULTI_USER");
success = true;
}
}
catch (SqlException e)
{
retry = false;
if (e.Message.IndexOf("was deadlocked on lock resources with another process and has been chosen as the deadlock victim") > 0)
{
retry = true;
retries++;
}
}
} while (success == false && (retry && retries < 3));
}
示例2: Delete
/// <summary>
/// 删除数据库重新创建
/// </summary>
/// <param name="context"></param>
public static void Delete(DataContext context)
{
context.DeleteDatabase();
Create(context);
}