예제 #1
0
        public static DbBase CreateConnection()
        {
            if (Enum.IsDefined(typeof(ConnectionTypes), Settings.Default.DbConnectionType))
                _connType = (ConnectionTypes)Settings.Default.DbConnectionType;
            else
                _connType = ConnectionTypes.Unknown;

            string connString = Settings.Default.DbConnectionString;
            string defaultSchema = Settings.Default.DbDefaultSchema;
            bool promptPwd = Settings.Default.DbPromptPwd;

            if ((_connType == ConnectionTypes.Unknown) || String.IsNullOrEmpty(connString) ||
                ((DbBase.GetBackend(connString, _connType) != Backends.Access) && String.IsNullOrEmpty(defaultSchema)))
            {
                promptPwd = false;
                SelectConnectionType();
            }

            if (_connType == ConnectionTypes.Unknown) return null;

            DbBase db = null;

            switch (_connType)
            {
                case ConnectionTypes.ODBC:
                    db = new DbOdbc(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone,
                        Settings.Default.DbTextLength, Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.OleDb:
                    db = new DbOleDb(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.Oracle:
                    db = new DbOracle(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.PostgreSQL:
                    db = new DbPgSql(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
                case ConnectionTypes.SQLServer:
                    db = new DbSqlServer(ref connString, ref defaultSchema, ref promptPwd,
                        Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                        true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                        Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                        Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                    break;
            }

            if (db != null)
            {
                Settings.Default.DbConnectionType = (int)_connType;
                Settings.Default.DbConnectionString = connString;
                Settings.Default.DbDefaultSchema = defaultSchema;
                Settings.Default.DbPromptPwd = promptPwd;
                Settings.Default.Save();
            }

            return db;
        }
예제 #2
0
        public static DbBase CreateConnection()
        {
            if (Enum.IsDefined(typeof(ConnectionTypes), Settings.Default.DbConnectionType))
            {
                _connType = (ConnectionTypes)Settings.Default.DbConnectionType;
            }
            else
            {
                _connType = ConnectionTypes.Unknown;
            }

            string connString    = Settings.Default.DbConnectionString;
            string defaultSchema = Settings.Default.DbDefaultSchema;
            bool   promptPwd     = Settings.Default.DbPromptPwd;

            if ((_connType == ConnectionTypes.Unknown) || String.IsNullOrEmpty(connString) ||
                ((DbBase.GetBackend(connString, _connType) != Backends.Access) && String.IsNullOrEmpty(defaultSchema)))
            {
                promptPwd = false;
                SelectConnectionType();
            }

            if (_connType == ConnectionTypes.Unknown)
            {
                return(null);
            }

            DbBase db = null;

            switch (_connType)
            {
            case ConnectionTypes.ODBC:
                db = new DbOdbc(ref connString, ref defaultSchema, ref promptPwd,
                                Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone,
                                Settings.Default.DbTextLength, Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.OleDb:
                db = new DbOleDb(ref connString, ref defaultSchema, ref promptPwd,
                                 Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                 true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                 Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                 Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.Oracle:
                db = new DbOracle(ref connString, ref defaultSchema, ref promptPwd,
                                  Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                  true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                  Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                  Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.PostgreSQL:
                db = new DbPgSql(ref connString, ref defaultSchema, ref promptPwd,
                                 Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                 true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                 Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                 Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;

            case ConnectionTypes.SQLServer:
                db = new DbSqlServer(ref connString, ref defaultSchema, ref promptPwd,
                                     Properties.Resources.PasswordMaskString, Settings.Default.UseAutomaticCommandBuilders,
                                     true, Settings.Default.DbIsUnicode, Settings.Default.DbUseTimeZone, Settings.Default.DbTextLength,
                                     Settings.Default.DbBinaryLength, Settings.Default.DbTimePrecision,
                                     Settings.Default.DbNumericPrecision, Settings.Default.DbNumericScale);
                break;
            }

            if (db != null)
            {
                Settings.Default.DbConnectionType   = (int)_connType;
                Settings.Default.DbConnectionString = connString;
                Settings.Default.DbDefaultSchema    = defaultSchema;
                Settings.Default.DbPromptPwd        = promptPwd;
                Settings.Default.Save();
            }

            return(db);
        }