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


C# DataContext.DatabaseExists方法代码示例

本文整理汇总了C#中DataContext.DatabaseExists方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.DatabaseExists方法的具体用法?C# DataContext.DatabaseExists怎么用?C# DataContext.DatabaseExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.DatabaseExists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connect

 public static void Connect(string connectionString, out string setConnectionString)
 {
     using (var db = new DataContext(connectionString))
     {
         if (!db.DatabaseExists())
             throw new RepositoryException(string.Format("База данных '{0}' отсутствует на сервере '{1}'",
                                                              db.Connection.Database,
                                                              db.Connection.DataSource));
         setConnectionString = connectionString;
     }
 }
开发者ID:aTEuCT,项目名称:Repository-Framework,代码行数:11,代码来源:RepositoryDMBase.cs

示例2: CreateUpdate

 /// <summary>
 /// 创建数据库并更新版本信息
 /// </summary>
 /// <param name="context"></param>
 public static void CreateUpdate(DataContext context)
 {
     if (!context.DatabaseExists())
     {
         Create(context);
     }
     else
     {
         Update(context);
     }
 }
开发者ID:uvbs,项目名称:MyProjects,代码行数:15,代码来源:DataBaseUtils.cs

示例3: dataContextByName

        public static DataContext dataContextByName(string db)
        {
            string conn = Config.CONNSTR(db);

            DataContext dc =new DataContext(conn);
            if (!dc.DatabaseExists()) {
                dc.CreateDatabase();

            }

            return dc;
        }
开发者ID:uhealin,项目名称:kull-mobile,代码行数:12,代码来源:DataContextFactory.cs

示例4: 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

示例5: ClearTpDB

		private static void ClearTpDB(DataContext tpDatabaseDataContext)
		{
            if (!tpDatabaseDataContext.DatabaseExists())
            {
                tpDatabaseDataContext.CreateDatabase();
                tpDatabaseDataContext.SubmitChanges();
            }
            else
            {
                tpDatabaseDataContext.ExecuteCommand("delete from Project");
                tpDatabaseDataContext.ExecuteCommand("delete from TpUser");
                tpDatabaseDataContext.ExecuteCommand("delete from General");
                tpDatabaseDataContext.ExecuteCommand("delete from MessageUid");
                tpDatabaseDataContext.ExecuteCommand("delete from PluginProfile");
                tpDatabaseDataContext.ExecuteCommand("delete from Revision");  
            }
		}
开发者ID:sbcfwebdev,项目名称:Target-Process-Plugins,代码行数:17,代码来源:LegacyProfileConversionActionSteps.cs

示例6: Run

        /// <summary>Run operation.</summary>
        public void Run(enumRun mode)
        {
            // Validate application configuration file.
            if(String.IsNullOrEmpty(_paramGetStatusesSince) || String.IsNullOrEmpty(_paramGetStatusesCount)) {
            EventLog.WriteEntry(logName, "Application Error: Missing values from configuration file.", EventLogEntryType.Error);
            return;
            }

            // Init database.
            _dbContext = new BaseDataContext(_dbConnectionString);
            if(!_dbContext.DatabaseExists()) {
            _dbContext.CreateDatabase();
            }

            // Create (INSERT) default data to database.
            if(mode == enumRun.LoadData) {
            CreateStatusesDefault();
            Console.WriteLine("\nLoaded data successfully.");
            } else if(mode == enumRun.LoadData) {
            Console.WriteLine("\nCannot load data because it exists. If you want to try again, then you must either drop the database or delete all the records.");
            }

            // Iterate and process users.
            TwitterStatus userStatus = null;
            string userUrlGetStatuses = String.Empty;
            var userIds = _paramGetStatusesUserValue.RemoveWhitespaces().Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
            for(int i = 0;i < userIds.Length;i += 1) {
            userUrlGetStatuses = String.Empty;
            // Get (SELECT) status, most recent.
            userStatus = GetStatusLatest(userIds[i]);
            // Validate status.
            if(userStatus != null) {
                userUrlGetStatuses = _urlGetStatuses.AppendQueryString(String.Concat(_paramGetStatusesSince, "=", userStatus.Id));
            } else {
                userUrlGetStatuses = _urlGetStatuses.AppendQueryString(String.Concat(_paramGetStatusesCount, "=", _paramDataStatusesHistory));
            }
            // Create (INSERT) statue from XML.
            CreateStatus(userUrlGetStatuses.AppendQueryString(String.Concat(_paramGetStatusesUser, "=", userIds[i])));
            }
            // Remove (DELETE) extra statuses based on maximum length.
            RemoveStatuses(_paramDataStatusesHistory);
            // Submit data changes.
            _dbContext.SubmitChanges();
        }
开发者ID:diehard,项目名称:native-dotnet-console,代码行数:45,代码来源:Twitter.cs

示例7: Run

        /// <summary>Run operation.</summary>
        public void Run(enumRun mode)
        {
            // Init database.
            _dbContext = new BaseDataContext(_dbConnectionString);
            if(!_dbContext.DatabaseExists()) {
            _dbContext.CreateDatabase();
            }

            // Get (SELECT) locations from database.
            var locations = GetLocations();
            int locationsLength = locations.Count();

            // Create (INSERT) default data to database.
            if(mode == enumRun.LoadData && (locations == null || locationsLength <= 0)) {
            locations = CreateLocationsDefault();
            Console.WriteLine("\nLoaded data successfully.");
            } else if(mode == enumRun.LoadData) {
            Console.WriteLine("\nCannot load data because it exists. If you want to try again, then you must either drop the database or delete all the records.");
            }

            // Process condition from each location.
            for(int i = 0;i < locationsLength;i += 1) {
            // Create (INSERT) condition from XML.
            CreateConditions(locations[i]);
            // Remove (DELETE) extra conditions based on maximum length.
            RemoveConditions(locations[i], _paramConditionHistory);
            }
            // Remove (DELETE) extra conditions based on maximum length.
            RemoveConditions(_paramConditionHistory);
            // Submit data changes.
            _dbContext.SubmitChanges();
        }
开发者ID:diehard,项目名称:native-dotnet-console,代码行数:33,代码来源:Weather.cs


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