Exemplo n.º 1
0
        private void btnConnect_Click(object sender, System.EventArgs e)
        {
            // Save contents of controls to XML file.
            // Data binding to radio buttons doesn't seem to work, sadly, so we have to do this bit manually.
            dsSettings.settings [0].SqlTrusted     = rbSqlTrusted.Checked;
            dsSettings.settings [0].OraMSDriver    = rbOraMSDriver.Checked;
            dsSettings.settings [0].ConnectionPage = tabControl.SelectedIndex;
            try { dsSettings.WriteXml(configFile); }
            catch (Exception) {}

            // Create DbClient (database client) object

            IClientFactory clientFactory;
            string         connectString, connectDescription;

            switch (tabControl.SelectedIndex)
            {
            case 0:                                                                             // SQL Server
                clientFactory = new SqlFactory();
                connectString = "Data Source=" + txtSqlServer.Text.Trim() + ";app=Query Express";
                if (rbSqlTrusted.Checked)
                {
                    connectString += ";Integrated Security=SSPI";
                }
                else
                {
                    connectString +=
                        ";User ID=" + txtSqlLoginName.Text.Trim() +
                        ";Password="******" (" +
                                     (rbSqlTrusted.Checked ? "Trusted" : txtSqlLoginName.Text.Trim()) + ")";
                break;

            case 1:                                                                             // Oracle
                // As we don't yet have Oracle .NET classes, use the OleDb family of classes instead.
                clientFactory = new OleDbFactory();
                connectString = "Provider="
                                + ((rbOraMSDriver.Checked) ? "MSDAORA" : "OraOLEDB.Oracle")
                                + ";Data Source=" + txtOraDataSource.Text.Trim()
                                + ";User ID=" + txtOraLoginName.Text.Trim() + ";Password="******"[" + connectString.Substring(0, Math.Min(25, connectString.Length)) + "...]";
                break;

            default:        return;
            }

            dbClient = new DbClient(clientFactory, connectString, connectDescription);
            Cursor oldCursor = Cursor;

            Cursor = Cursors.WaitCursor;

            ConnectingForm c = new ConnectingForm();

            c.Show();
            c.Refresh();
            bool success = dbClient.Connect();

            c.Close();
            Cursor = oldCursor;

            if (!success)
            {
                MessageBox.Show("Unable to connect: " + dbClient.Error, "Query Express", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dbClient.Dispose();
                return;
            }

            // Create a browser object (if available for the provider)

            if (tabControl.SelectedIndex == 0)                                                  // SQL Server
            {
                browser = new SqlBrowser(dbClient);
            }

            if (tabControl.SelectedIndex == 1)                                                  // Oracle
            {
                browser = new OracleBrowser(dbClient);
            }

            if (tabControl.SelectedIndex == 2)                                                  // OleDb
            {
                browser = new dl3bak.OleDbBrowser(dbClient);
            }

            DialogResult = DialogResult.OK;
        }
Exemplo n.º 2
0
        private void btnConnect_Click(object sender, System.EventArgs e)
        {
            // Save contents of controls to XML file.
            // Data binding to radio buttons doesn't seem to work, sadly, so we have to do this bit manually.
            dsSettings.settings [0].SqlTrusted = rbSqlTrusted.Checked;
            dsSettings.settings [0].OraMSDriver = rbOraMSDriver.Checked;
            dsSettings.settings [0].ConnectionPage = tabControl.SelectedIndex;
            try { dsSettings.WriteXml (configFile); }
            catch (Exception) {}

            // Create DbClient (database client) object

            IClientFactory clientFactory;
            string connectString, connectDescription;

            switch (tabControl.SelectedIndex)
            {
                case 0:								// SQL Server
                    clientFactory = new SqlFactory();
                    connectString = "Data Source=" + txtSqlServer.Text.Trim() + ";app=Query Express";
                    if (rbSqlTrusted.Checked)
                        connectString +=  ";Integrated Security=SSPI";
                    else
                        connectString +=
                            ";User ID=" + txtSqlLoginName.Text.Trim() +
                            ";Password="******" (" +
                        (rbSqlTrusted.Checked ? "Trusted" : txtSqlLoginName.Text.Trim()) + ")";
                    break;

                case 1:								// Oracle
                    // As we don't yet have Oracle .NET classes, use the OleDb family of classes instead.
                    clientFactory = new OleDbFactory();
                    connectString = "Provider="
                        + ((rbOraMSDriver.Checked) ? "MSDAORA" : "OraOLEDB.Oracle")
                        + ";Data Source=" + txtOraDataSource.Text.Trim()
                        + ";User ID=" + txtOraLoginName.Text.Trim() + ";Password="******"[" + connectString.Substring (0, Math.Min (25, connectString.Length)) + "...]";
                    break;

                default:	return;
            }

            dbClient = new DbClient (clientFactory, connectString, connectDescription);
            Cursor oldCursor = Cursor;
            Cursor = Cursors.WaitCursor;

            ConnectingForm c = new ConnectingForm();
            c.Show();
            c.Refresh();
            bool success = dbClient.Connect();
            c.Close();
            Cursor = oldCursor;

            if (!success)
            {
                MessageBox.Show ("Unable to connect: " + dbClient.Error, "Query Express", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dbClient.Dispose();
                return;
            }

            // Create a browser object (if available for the provider)

            if (tabControl.SelectedIndex == 0)					// SQL Server
                browser = new SqlBrowser (dbClient);

            if (tabControl.SelectedIndex == 1)					// Oracle
                browser = new OracleBrowser (dbClient);

            if (tabControl.SelectedIndex == 2)					// OleDb
                browser = new dl3bak.OleDbBrowser (dbClient);

            DialogResult = DialogResult.OK;
        }