Exemple #1
0
        /// <summary>
        /// 检测数据库
        /// </summary>
        private bool CheckDBState()
        {
            // 逻辑:检测数据库没有主数据库名时查看文件,有文件附加,备数据库没文件时同步主备数据库有文件则附加
            bool bl   = false;
            bool falg = true;

            try
            {
                if (!Open())
                {
                    return(false);
                }
                foreach (Database db in svr.Databases)
                {
                    if (db.Name != null && db.Name.ToLowerInvariant() == dbName)
                    {
                        bl = true;
                        break;
                    }
                }

                if (!bl)
                {
                    if (File.Exists(dbPath + dbName + ".mdf"))
                    {
                        svr.AttachDB(dbName, dbPath + dbName + ".mdf;" + dbPath + dbName + "_log.ldf");
                    }
                    else
                    {
                        ErrorMessage(2024001, "", "[DataBaseManage:CheckDBState]", "没有发现kj128数据库");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage(6024002, ex.StackTrace, "[DataBaseManage:CheckDBState]", ex.Message);
                falg = false;
            }
            //finally
            //{
            //    LinkNull(svr);
            //}
            return(falg);
        }