Esempio n. 1
0
        /// <summary>
        /// Handles event when Ok button is clicked
        /// </summary>
        /// <param name="param"></param>
        /// <remarks></remarks>
        private void OkCommandClick(object param)
        {
            OdbcConnection cn;

            try
            {
                cn = new OdbcConnection(_connStrBuilder.ConnectionString);

                cn.Open();
                cn.Close();

                if (DbOdbc.GetBackend(cn) == Backends.Access)
                {
                    _defaultSchema = String.Empty;
                }

                this.RequestClose(_connStrBuilder.ConnectionString, _defaultSchema, null);
            }
            catch (OdbcException exOdbc)
            {
                MessageBox.Show("ODBC Server responded with an error:\n\n" + exOdbc.Message,
                                "ODBC Server Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally { cn = null; }
        }
Esempio n. 2
0
        public static Backends GetBackend(string connString, ConnectionTypes connType)
        {
            switch (connType)
            {
            case ConnectionTypes.ODBC:
                return(DbOdbc.GetBackend(connString));

            case ConnectionTypes.OleDb:
                return(DbOleDb.GetBackend(connString));

            default:
                return(Backends.Undetermined);
            }
        }
Esempio 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;
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void LoadSchemata()
        {
            List <String>  schemaList = new List <String>();
            OdbcConnection cn         = null;

            try
            {
                if ((_connStrBuilder != null) && !String.IsNullOrEmpty(_connStrBuilder.ConnectionString))
                {
                    cn = new OdbcConnection(_connStrBuilder.ConnectionString);
                    cn.Open();

                    _backend = DbOdbc.GetBackend(cn);

                    if (_backend != Backends.Access)
                    {
                        OdbcCommand cmd = cn.CreateCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "SELECT SCHEMA_NAME FROM information_schema.schemata" +
                                          " WHERE SCHEMA_NAME <> 'INFORMATION_SCHEMA'";
                        OdbcDataAdapter adapter = new OdbcDataAdapter(cmd);
                        DataTable       dbTable = new DataTable();
                        try
                        {
                            adapter.Fill(dbTable);
                            schemaList = (from r in dbTable.AsEnumerable()
                                          let schemaName = r.Field <string>("SCHEMA_NAME")
                                                           select schemaName).OrderBy(s => s).ToList();
                            _defaultSchema = DbBase.GetDefaultSchema(_backend, _connStrBuilder, schemaList);
                        }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                _connStrBuilder.Dsn = String.Empty;
                if (ex is OdbcException)
                {
                    MessageBox.Show(ex.Message, "ODBC Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, "HLU Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            finally
            {
                if ((cn != null) && (cn.State != ConnectionState.Closed))
                {
                    cn.Close();
                }

                _schemata = schemaList;
                OnPropertyChanged("Schemata");

                if (_schemata.Count == 1)
                {
                    _defaultSchema = _schemata[0];
                }
                OnPropertyChanged("DefaultSchema");
            }
        }