Results 1 to 5 of 5

Thread: [SOLVED][2005]test connection connected ...? how?

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    172

    [SOLVED][2005]test connection connected ...? how?

    Hi guys,

    I have got a test connection button which tests the connectionstring that is been made by the user by typing in all relevant info.

    How do i check whether it has connected or it cant connect due to a faulty password for example.


    heres my code:

    currently i am using the state property but everytime it cant connect it just breaks the program, saying it cant hold a null value or something.

    Code:
       Private Sub bntTestConn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntTestConn.Click
            Dim myConnection As New SqlConnection
    
            If rdoWinAuth.Checked = True Then
                Dim WinConn As New ServerConnection
                Dim server As New Server(WinConn)
    
                WinConn.LoginSecure = True
                WinConn.DatabaseName = txtSQLDatabase.Text
                WinConn.ServerInstance = txtSQLServer.Text
    
                'Open the Win Connection
                'WinConn.Connect()
    
                If server.State = 0 Then
                    MsgBox(" Unable to establish an SQL connection - Connection Failed")
                Else : MsgBox("Connection Succesfull")
                End If
    
    
                'Close the Win connection
                WinConn.Disconnect()
            End If
    
            If rdoSecAuth.Checked = True Then
                Dim SecConn As New ServerConnection
                Dim server As New Server(SecConn)
    
             
    
                If txtPassword.Text = "" Or txtUserName.Text = "" Then
                    MsgBox("Please enter your Username/Password")
                Else
    
                    'Declare the connectionstring
                    SecConn.LoginSecure = False
                    SecConn.DatabaseName = txtSQLServer.Text
                    SecConn.ServerInstance = txtSQLDatabase.Text
                    SecConn.Login = txtUserName.Text
                    SecConn.Password = txtPassword.Text
    
                  
                    'Open the Sec connection 
                    SecConn.Connect()
    
                    If server.State = 0 Then
                        MsgBox(" Unable to establish an SQL connection - Connection Failed")
                    Else : MsgBox("Connection Succesfull")
                    End If
    
                    'Close the Sec connection
                    SecConn.Disconnect()
                End If
            End If
        End Sub
    Any help is appreciated.

    Thanks!

    Rob
    Last edited by Devdude; Oct 9th, 2007 at 06:06 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width