Beispiel #1
0
        private void serverSelectionChanged(object sender)
        {
            databases.Items.Clear();

            ArrayList sortedDBs = new ArrayList();

            String currentDBServer = textBox_Server.Text;
            String currentDBServerPort = "";

            if (textBox_Port.Text == "")
            {
                if (databaseServers.SelectedItem != null)
                    currentDBServerPort = ((ComboBoxServer)databaseServers.SelectedItem).Port;
                else
                    currentDBServerPort = textBox_Port.Text;
                textBox_Port.Text = currentDBServerPort;
            }
            else
                currentDBServerPort = textBox_Port.Text;

            TextBlockStatus.Text = "Verfügbare Datenbanken werden in " + currentDBServer + " gesucht.";

            if (comboBoxDBType.SelectedItem.ToString() == DBPOSTGRES)
            {
                this.databases.Items.Clear();
                this.hisProduct.Items.Clear();
                this.comboBoxEncoding.Items.Clear();

                DBConnection pgConnection = new DBConnection(DBConnection.DBType.Postgres);
                NpgsqlConnection sqlConx = (NpgsqlConnection)pgConnection.openPGConnection(currentDBServer, "postgres", currentDBServerPort, getHisProduct(), false);

                if (sqlConx == null)
                {
                    TextBlockStatus.Text = "Datenbank Verbindung fehlgeschlagen!";
                    return;
                }

                DataTable tblDatabases = sqlConx.GetSchema("Databases");
                DataView view = tblDatabases.DefaultView;
                view.Sort = "database_name";

                sqlConx.Close();

                foreach (DataRowView row in view)
                {
                    try
                    {
                        String dbName = row["database_name"].ToString().Trim();
                        String dbOwner = row["owner"].ToString().Trim();
                        String dbEncoding = row["encoding"].ToString().Trim();

                        if ((dbName != "postgres") && (dbName != "template0") && (dbName != "template1") && (dbName != "latin1"))
                        {
                            sortedDBs.Add(new ComboBoxDatabase(dbName, dbOwner, dbEncoding));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message);
                        return;
                    }
                }
            }
            else if (comboBoxDBType.SelectedItem.ToString() == DBINFORMIX)
            {
                if (databaseServers.SelectedItem == null)
                    return;
                String currentInformixServer = ((ComboBoxServer)databaseServers.SelectedItem).InformixServer;

                if (!SQLHosts.EntryExists(currentInformixServer))
                {
                    SQLHosts.CreateEntry(currentInformixServer, currentDBServer, currentDBServerPort);
                }

                try
                {
                    DBConnection ifxConnection = new DBConnection(DBConnection.DBType.Informix);

                    IfxConnection conn = (IfxConnection)ifxConnection.openIfxConnection(currentDBServer, currentInformixServer, "sysmaster", currentDBServerPort, getHisProduct(), "", false);

                    if (conn == null)
                    {
                        TextBlockStatus.Text = "Datenbank Verbindung fehlgeschlagen!";
                        return;
                    }

                    String commandText = "SELECT sysdatabases.name, sysdatabases.owner, sysdbslocale.dbs_collate " +
                                         "FROM sysdbslocale INNER JOIN sysdatabases ON sysdatabases.name = sysdbslocale.dbs_dbsname " +
                                         "ORDER BY sysdatabases.name;";

                    IfxDataReader reader = (IfxDataReader)ifxConnection.readQuery(commandText);

                    // reader.HasRows was returning FALSE on some machines when there were rows returned
                    while ((reader != null) && reader.Read())
                    {
                        String dbName = reader[0].ToString().Trim();
                        String dbOwner = reader[1].ToString().Trim();
                        String dbEncoding = reader[2].ToString().Trim();
                        if (!dbName.StartsWith("sys"))
                        {
                            sortedDBs.Add(new ComboBoxDatabase(dbName, dbOwner, dbEncoding));
                        }
                    }

                    conn.Close();
                    conn.Dispose();

                }
                catch (IfxException ex)
                {
                    MessageBox.Show("Failed opening connection: " + ex);
                    TextBlockStatus.Text = "Datenbank Verbindung fehlgeschlagen!";
                    return;
                }
                catch (TypeInitializationException ex)
                {
                    MessageBox.Show("Failed opening connection: " + ex);
                    TextBlockStatus.Text = "Datenbank Verbindung fehlgeschlagen!";
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed opening connection: " + ex);
                    TextBlockStatus.Text = "Datenbank Verbindung fehlgeschlagen!";
                    return;
                }

            }

            this.databases.Items.Clear();
            foreach (ComboBoxDatabase db in sortedDBs)
            {
                this.databases.Items.Add(db);
            }
            // filter when called normally
            if (sender != null)
                textBox_filterDBs_TextChanged(null, null);
            TextBlockStatus.Text = "Server " + currentDBServer + " hat " + databases.Items.Count + " Datenbanken verfügbar.";
        }
Beispiel #2
0
        private DBConnection DBConnectionSetup()
        {
            if ((databases.SelectedItem == null) || ((databaseServers.SelectedItem == null) && (this.textBox_Server.Text == "")))
                return null;
            String dbServerName = textBox_Server.Text;
            String dbServerPort = textBox_Port.Text;
            String dbName = ((ComboBoxDatabase)(databases.SelectedItem)).Name;

            DBConnection dbconn = new DBConnection((comboBoxDBType.SelectedItem.ToString() == DBPOSTGRES) ? DBConnection.DBType.Postgres : DBConnection.DBType.Informix);

            if (comboBoxDBType.SelectedItem.ToString() == DBPOSTGRES)
            {
                dbconn.openPGConnection(dbServerName, dbName, dbServerPort, getHisProduct(), false);
            }
            else
            {
                String ifxServerName = ((ComboBoxServer)(databaseServers.SelectedItem)).InformixServer;
                String currentInformixLocale = ((ComboBoxDatabase)databases.SelectedItem).Encoding;
                dbconn.openIfxConnection(dbServerName, ifxServerName, dbName, dbServerPort, getHisProduct(), currentInformixLocale, false);
            }

            return dbconn;
        }