Exemplo n.º 1
0
        public static string GetDefaultSchema(Backends backend,
                                              DbConnectionStringBuilder connStrBuilder, List <string> schemata)
        {
            switch (backend)
            {
            case Backends.Access:
                return(null);

            case Backends.PostgreSql:
                return("public");

            case Backends.SqlServer:
                return("dbo");

            case Backends.Oracle:
                if ((connStrBuilder != null) && (connStrBuilder.ContainsKey("USER ID")))
                {
                    string userIDstring = DbOracle.GetUserId(connStrBuilder);
                    if ((schemata != null) && (schemata.IndexOf(userIDstring) != -1))
                    {
                        return(userIDstring);
                    }
                }
                return(null);

            default:
                if (connStrBuilder != null)
                {
                    object userID;
                    if ((connStrBuilder.TryGetValue("UID", out userID)) ||
                        (connStrBuilder.TryGetValue("User ID", out userID)))
                    {
                        string userIDstring = userID.ToString();
                        if ((schemata != null) && (schemata.IndexOf(userIDstring) != -1))
                        {
                            return(userIDstring);
                        }
                    }
                }
                return(null);
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
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);
        }