Exemplo n.º 1
0
        public void CheckDatabase()
        {
            if (strUtil.IsNullOrEmpty(this._connectionString))
            {
                throw new Exception("connection string can not be empty");
            }
            IDatabaseDialect dialect = DataFactory.GetDialect(DatabaseType.MySql);

            if (strUtil.IsNullOrEmpty(dialect.GetConnectionItem(this._connectionString, ConnectionItemType.Server)))
            {
                throw new Exception("[mysql] server address is empty");
            }
            if (strUtil.IsNullOrEmpty(dialect.GetConnectionItem(_connectionString, ConnectionItemType.Database)))
            {
                throw new Exception("[mysql] database is empty");
            }
        }
Exemplo n.º 2
0
        public void CheckDatabase()
        {
            if (strUtil.IsNullOrEmpty(this._connectionString))
            {
                throw new Exception("[MySQL] 数据库连接字符串未设置");
            }
            IDatabaseDialect dialect = DataFactory.GetDialect(DatabaseType.MySql);

            if (strUtil.IsNullOrEmpty(dialect.GetConnectionItem(this._connectionString, ConnectionItemType.Server)))
            {
                throw new Exception("[MySQL] 未指定目标数据库服务器地址");
            }
            if (strUtil.IsNullOrEmpty(dialect.GetConnectionItem(_connectionString, ConnectionItemType.Database)))
            {
                throw new Exception("[MySQL] 未指定目标数据库名称");
            }
        }
Exemplo n.º 3
0
        public void CheckDatabase()
        {
            if (strUtil.IsNullOrEmpty(_connectionString))
            {
                throw new Exception("[sqlserver] connection String is not found");
            }
            IDatabaseDialect dialect = DataFactory.GetDialect(DatabaseType.SqlServer);

            if (strUtil.IsNullOrEmpty(dialect.GetConnectionItem(_connectionString, ConnectionItemType.Server)))
            {
                throw new Exception("[sqlserver] address is empty");
            }
            if (strUtil.IsNullOrEmpty(dialect.GetConnectionItem(_connectionString, ConnectionItemType.Database)))
            {
                throw new Exception("[sqlserver] database is empty");
            }
        }
Exemplo n.º 4
0
        private static void checkConnectionString(DbConfig result)
        {
            logger.Info("checkConnectionString...");

            if (result.ConnectionStringTable == null)
            {
                return;
            }

            Dictionary <String, ConnectionString> connStringMap = new Dictionary <String, ConnectionString>();

            Dictionary <String, String> newString = new Dictionary <String, String>();

            foreach (KeyValuePair <String, String> kv in result.ConnectionStringTable)
            {
                String       connectionString = kv.Value;
                DatabaseType dbtype           = getDbType(kv.Key, connectionString, result);

                ConnectionString objConnString = new ConnectionString {
                    Name          = kv.Key,
                    StringContent = connectionString,
                    DbType        = dbtype
                };

                connStringMap.Add(kv.Key, objConnString);

                logger.Info("connectionString:" + connectionString);

                IDatabaseDialect dialect = DataFactory.GetDialect(dbtype);

                if ((dbtype == DatabaseType.Access))
                {
                    String connectionItem = dialect.GetConnectionItem(connectionString, ConnectionItemType.Database);
                    logger.Info("database path original:" + connectionItem);
                    if (connectionItem == null)
                    {
                        throw new Exception("没有设置access地址:" + connectionString);
                    }

                    if (IsRelativePath(connectionItem))
                    {
                        connectionItem = PathHelper.Map(strUtil.Join(SystemInfo.ApplicationPath, connectionItem));
                        logger.Info("database path now:" + connectionItem);
                        String newConnString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", connectionItem);

                        newString.Add(kv.Key, newConnString);
                    }
                }
            }

            foreach (KeyValuePair <String, String> kv in newString)
            {
                result.ConnectionStringTable[kv.Key] = kv.Value;
                connStringMap[kv.Key].StringContent  = kv.Value;
            }

            result.SetConnectionStringMap(connStringMap);
        }
Exemplo n.º 5
0
        private static void checkConnectionString(DbConfig result)
        {
            logger.Info("检查数据库连接设置...");

            if (result.ConnectionStringTable == null)
            {
                return;
            }

            Dictionary <String, ConnectionString> connStringMap = new Dictionary <String, ConnectionString>();

            Dictionary <String, String> newString = new Dictionary <string, string>();

            foreach (KeyValuePair <String, object> kv in result.ConnectionStringTable)
            {
                String       connectionString = kv.Value.ToString();
                DatabaseType dbtype           = getDbType(kv.Key, connectionString, result);

                ConnectionString objConnString = new ConnectionString();
                objConnString.Name          = kv.Key;
                objConnString.StringContent = connectionString;
                objConnString.DbType        = dbtype;

                connStringMap.Add(kv.Key, objConnString);

                logger.Info("链接字符串:" + connectionString);

                IDatabaseDialect dialect = DataFactory.GetDialect(dbtype);

                if ((dbtype == DatabaseType.Access))
                {
                    String connectionItem = dialect.GetConnectionItem(connectionString, ConnectionItemType.Database);
                    logger.Info("database path original:" + connectionItem);

                    if (IsRelativePath(connectionItem))
                    {
                        connectionItem = strUtil.Join(SystemInfo.ApplicationPath, connectionItem);
                        //connectionItem = PathHelper.Map( strUtil.Join( SystemInfo.ApplicationPath, connectionItem ) );
                    }
                    logger.Info("database path now:" + connectionItem);
                    String newConnString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", connectionItem);
                    newString.Add(kv.Key, newConnString);
                    if (!file.Exists(connectionItem))
                    {
                        try
                        {
                            object catobj = null;
                            try
                            {
                                catobj = rft.GetInstance("Interop.ADOX", "ADOX.CatalogClass");
                            }
                            catch
                            {
                                logger.Error("Interop.ADOX.dll文件不存在,请检查bin目录!");
                            }
                            object connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + connectionItem + ";" +
                                             "Jet OLEDB:Engine Type=5";
                            rft.CallMethod(catobj, "Create", new[] { connstr });
                            //ADOX.CatalogClass cat = new ADOX.CatalogClass();
                            //cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + connectionItem + ";" + "Jet OLEDB:Engine Type=5");
                            //Console.WriteLine("Database Created Successfully");
                            //logger.Info("Access数据库已创建:" + connectionItem);
                            //cat = null;
                        }
                        catch
                        {
                            logger.Info("Access数据库创建失败:" + connectionItem);
                        }
                    }
                }
            }

            foreach (KeyValuePair <String, String> kv in newString)
            {
                result.ConnectionStringTable[kv.Key] = kv.Value;
                connStringMap[kv.Key].StringContent  = kv.Value;
            }

            result.SetConnectionStringMap(connStringMap);
        }