Example #1
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);
        }
Example #2
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 );
        }
Example #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);
        }
Example #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, 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 );
        }