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.
Any help is appreciated.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
Thanks!
Rob![]()




Reply With Quote