|
-
Mar 29th, 2002, 02:48 PM
#1
Testing a connection to see if it works
I have a connection string i want to test to see if its valid...meaning it can connect to a db. How is this done?
-
Mar 29th, 2002, 02:53 PM
#2
Hyperactive Member
here is what I do to make and test connection strings. create a new textfile.. rename it to <anything>.UDL Then open up the file and set your connection properties (choose providor, point to your db) then there is a button called labeled 'Test Connection'. This will, obviously, test your connection.
Now, here is the cool part.. open up notepad.. drag this udl file and drop it into notepad.. this will write out your connection string
-mcd
[vbcode]
'*****************************
MsgBox "MCD :: [email protected]", vbInformation + vbOKOnly, "User"
'*****************************
[/vbcode]
-
Mar 29th, 2002, 02:55 PM
#3
i've already done all of that...i just want a way to see if the connectionstring supplied is valid or not
-
Mar 29th, 2002, 02:56 PM
#4
^ without having to hit the test connection....in code
-
Jan 31st, 2004, 08:18 PM
#5
Hyperactive Member
I also had the same questions and this is what I deemed to do the trick.
Function VerifyConnection(ConnectionString As String) As Boolean
On Error GoTo ErrorHandler
Dim Cn As New ADODB.Connection
Cn.CursorLocation = adUseClient
Cn.ConnectionString = ConnectionString
Cn.ConnectionTimeout = 3
' open connection
Cn.Open
' Close connection
Cn.Close
ErrorHandler:
If Err.Number <> 0 Then
VerifyConnection = False
else
VerifyConnection = True
end if
End Function
-
Jan 31st, 2004, 10:23 PM
#6
Hyperactive Member
You can also use the following code to test the connection say cnn is your ado connection
you can use
VB Code:
if cnn.state <> adStateOpen then
msgbox"Cannot open the connection"
endif
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
|