当前位置: 首页>>代码示例>>C#>>正文


C# DataContext.DeleteDatabase方法代码示例

本文整理汇总了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));
        }
开发者ID:consumentor,项目名称:Server,代码行数:47,代码来源:DatabaseSpecBase.cs

示例2: Delete

 /// <summary>
 /// 删除数据库重新创建
 /// </summary>
 /// <param name="context"></param>
 public static void Delete(DataContext context)
 {
     context.DeleteDatabase();
     Create(context);
 }
开发者ID:uvbs,项目名称:MyProjects,代码行数:9,代码来源:DataBaseUtils.cs


注:本文中的DataContext.DeleteDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。