Exemple #1
0
 private static void testDbConnection(DBAccess _instance)
 {
     DataBaseAccess dba = _instance.CreateInstance();
     try
     {
         dba.ExecuteScalar("SELECT 1");
     }
     catch (Exception exc)
     {
         throw new Exception("[" + dba.DbType.ToString() + "]数据库连接失败,请检查连接信息是否有正确!");
     }
 }
Exemple #2
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        public static void Initialize(string connectionString,string dataTablePrefix)
        {
            if (String.IsNullOrEmpty(connectionString))
            {
                throw new NullReferenceException("请检查系统是否被授权或使用CmsDataBase.Initialize初始化数据库连接");
            }
            connectionString = connectionString.Replace("$ROOT",FwCtx.PhysicalPath);
            DataBaseType dbType=DataBaseType.MySQL;
            DataBaseAccess db= DBAccessCreator.GetDbAccess(connectionString, ref dbType);
            _instance = new DBAccess(dbType, db.DataBaseAdapter.ConnectionString);
            _instance.TablePrefix = dataTablePrefix;

            //测试数据库连接
            testDbConnection(_instance);
        }