Beispiel #1
0
        /// <summary>
        /// 测试数据库连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTestConnectSQL_Click(object sender, EventArgs e)
        {
            try
            {
                dbHelper = new DBHelperOracle(txtOracleAddress.Text, txtName.Text, txtPassword.Text);
                DBHelperOracle.init();
                MessageBox.Show("数据库连接成功!", "测试结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败: " + ex.Message, "测试结果", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            /*
             * Try
             *
             * 'get the selected connection
             * Dim strFullConn As String = Me.cboConnections.SelectedItem.ToString
             * Dim arrayFullConn() As String = strFullConn.Split("|")
             * Dim strDBType As String = arrayFullConn(0).ToUpper
             * Dim strDBConnOrig As String = arrayFullConn(1)
             * Dim strDBConn As String = arrayFullConn(1)
             *
             * 'check password
             * If Not CheckPassword(strDBConn) Then Exit Sub
             *
             * 'open the connection based on the connection type
             * Dim connSQLServer As SqlConnection = Nothing
             * Dim connOracle As OracleConnection = Nothing
             * If strDBType = "SQLSERVER" Then
             *  connSQLServer = New SqlConnection(strDBConn)
             *  connSQLServer.Open()
             *  connSQLServer.Close()
             * ElseIf strDBType = "ORACLE" Then
             *  connOracle = New OracleConnection(strDBConn)
             *  connOracle.Open()
             *  connOracle.Close()
             * End If
             *
             * 'connection worked - store password
             * If Not m_hashPasswords.Contains(strDBConnOrig) Then
             *  m_hashPasswords.Add(strDBConnOrig, m_strPassword)
             * End If
             *
             * MessageBox.Show("Connection succeeded", "Test Result", MessageBoxButtons.OK, MessageBoxIcon.Information)
             *
             * Catch ex As Exception
             * MessageBox.Show("Connection Failed: " + ex.Message, "Test Result", MessageBoxButtons.OK, MessageBoxIcon.Warning)
             * End Try*/
        }