|
-
Oct 5th, 2007, 03:29 AM
#1
Thread Starter
Addicted Member
[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.
-
Oct 5th, 2007, 04:19 AM
#2
Re: [2005]test connection connected ...? how?
The only way to test a connection is to open it:
vb.net Code:
Try
myConnection.Open()
myConnection.Close()
MessageBox.Show("Success")
Catch ex As Excpetion
MessageBox.Show("Failure")
End Try
-
Oct 5th, 2007, 05:52 AM
#3
Thread Starter
Addicted Member
Re: [2005]test connection connected ...? how?
Thanks JMC that seems to work and show me a message box.
Only problem still is that it still highlights the line showing up an error:
Failed to connect to server2.
What can i do about this?
Thanks,
Rob
-
Oct 5th, 2007, 05:54 AM
#4
Thread Starter
Addicted Member
Re: [2005]test connection connected ...? how?
ok sorry about that,
i think i will be able to figure that one out.
i think i understand why its doing that.
my code needs a little facelift.
ill post back my final result and let you know how its going.
Thanks,
Rob
-
Oct 8th, 2007, 03:45 AM
#5
Thread Starter
Addicted Member
Re: [2005]test connection connected ...? how?
Thanks JMC,
That worked out fine, so far I do not have any issues.
Thanks for helping me out with this one!

Rob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|