예제 #1
0
        /// <summary>
        /// Handles event when Ok button is clicked
        /// </summary>
        /// <param name="param"></param>
        /// <remarks></remarks>
        private void OkCommandClick(object param)
        {
            OleDbConnection cn;

            try
            {
                _connStrBuilder.PersistSecurityInfo = Settings.Default.DbConnectionPersistSecurityInfo;

                cn = new OleDbConnection(_connStrBuilder.ConnectionString);

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

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

                this.RequestClose(_connStrBuilder.ConnectionString, _defaultSchema, null);
            }
            catch (OleDbException exOleDb)
            {
                MessageBox.Show("OleDb Server responded with an error:\n\n" + exOleDb.Message,
                                "OleDb Server Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally { cn = null; }
        }
예제 #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);
            }
        }
예제 #3
0
        private void LoadSchemata()
        {
            List <String>   schemaList = new List <String>();
            OleDbConnection cn         = null;

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

                    _backend = DbOleDb.GetBackend(cn);

                    if (_backend != Backends.Access)
                    {
                        OleDbCommand cmd = cn.CreateCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA" +
                                          " WHERE SCHEMA_NAME <> 'INFORMATION_SCHEMA'";
                        OleDbDataAdapter adapter = new OleDbDataAdapter(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.ConnectionString = String.Empty;
                if (ex is OleDbException)
                {
                    MessageBox.Show(ex.Message, "OleDb 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");
            }
        }