public void AddDatabase(string userID, string password, string server, string db)
        {
            /*if (conString.ToLower().Contains("connection timeout"))
            {
                int startI = conString.ToLower().IndexOf("connection timeout");
                int endI = conString.IndexOf(";", startI);

                if (endI != -1)
                    conString = conString.Remove(startI, endI - startI);
                else
                    conString = conString.Substring(0, startI);
            }*/

            if (this._dbStringMap.ContainsKey(db))
                return;

            var cs = new ConnectionString(userID, password, server, db);
            this.AddDBConnectionString(db, cs);
        }
 /// <summary>
 /// Constructor for connection string
 /// </summary>
 public TableUpdateTimeCacheAll(ConnectionString connectionString, string onlyCheckDatabase = null)
 {
     this.checkOnlyDatabase = onlyCheckDatabase;
     this.multiCon = new MultiCon(connectionString);
 }
Beispiel #3
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 );
        }
 public void AddDBConnectionString(string db, ConnectionString cs)
 {
     this._dbStringMap.Add(db, cs);
 }
Beispiel #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);
        }
Beispiel #6
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, 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:" + 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 );
                    }
                }
            }

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

            result.SetConnectionStringMap( connStringMap );
        }