-
vba code to test odbc connection
How can i test an ODBC connection in VBA code.
I use DAO recordsets.
I know this question is already been raised on this forum, but it's never been answered.
I'd like to write a function like TestConnection = true or false or something
The connection string is like :
"ODBC;DATABASE=namedatabase;DESCRIPTION=x;DSN=x;OPTION=2346;PWD=x;PORT=0;SE RVER=x;UID=x"
Any help would be appreciated alot
-
DAO probably has an Errors collection, but IMHO ADO is probably a better route; and I would think you would want to emply DNS-less Connection Strings. Anyway, check out the errors collection here.
http://www.w3schools.com/ado/ado_ref_connection.asp
.02 Stan
-
problem solved !
Hi Stan,
Thanx for the reply. I've used your ADO-way. This is the code that
works for me.
Dim con
Set con = CreateObject("ADODB.Connection")
con.Open CONNSTRINGS
con.Close
Set con = Nothing
Where CONNSTRINGS is my connection string.
If the server is not online, my error trap gives the "no connection" message.
Thanks alot.
I'm new to ODBC connection. I'm gonna check out the differences between DSN and DSNless connections, because that's all a bit of Chinese for me right now
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