473,385 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Test for Valid ODBC Connection

Hello,

I am in the process of 'figuring out' how to verify if I have a valid
connection to an ODBC data source (SQL Server 2000). I've written code to
run a pass-through query against a table that is in the database. If the
query fails, I want the function to return a 'FALSE'. The code works fine
if the connection exists (returns 'TRUE'). However, if the connection is
invalid, I am forced to deal with an ODBC login dialog box that I can't seem
to suppress.

Perhaps I'm tackling this wrong. Has anybody tried to accomplish this same
task? If so, how did you do it?

Here's my code, for review:

************************************************** *********************
Public Function CheckSQLLinks() As Boolean
' Check links to a table (strSampleSQLTableName constant) defined
' in the module 'modPublic' module. Returns True if links are OK.

Dim db1 As Database, rs1 As Recordset, strSQL1 As String

On Error GoTo ErrOnLink

Set db1 = CurrentDb
strSQL1 = "SELECT " & strSampleSQLTableName & ".* " & "FROM " &
strSampleSQLTableName & ";"

Set rs1 = db1.OpenRecordset(strSQL1, dbOpenDynaset)

'Connection is OK, continue
CheckSQLLinks = True

ExitOnLink:
db1.Close
Exit Function

ErrOnLink:
CheckSQLLinks = False
GoTo ExitOnLink

End Function
************************************************** *************************

Thanks,
Scott
Nov 13 '05 #1
2 17557
Hi Scott,
just tried your code - works fine at me, no ODBC login dialog. I tried on
access XP. What Access version you using?

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com
"Scott A. Jones" <sa*****@gmx.net> wrote in message
news:ci*********@enews1.newsguy.com...
Hello,

I am in the process of 'figuring out' how to verify if I have a valid
connection to an ODBC data source (SQL Server 2000). I've written code to
run a pass-through query against a table that is in the database. If the
query fails, I want the function to return a 'FALSE'. The code works fine
if the connection exists (returns 'TRUE'). However, if the connection is
invalid, I am forced to deal with an ODBC login dialog box that I can't seem to suppress.

Perhaps I'm tackling this wrong. Has anybody tried to accomplish this same task? If so, how did you do it?

Here's my code, for review:

************************************************** *********************
Public Function CheckSQLLinks() As Boolean
' Check links to a table (strSampleSQLTableName constant) defined
' in the module 'modPublic' module. Returns True if links are OK.

Dim db1 As Database, rs1 As Recordset, strSQL1 As String

On Error GoTo ErrOnLink

Set db1 = CurrentDb
strSQL1 = "SELECT " & strSampleSQLTableName & ".* " & "FROM " &
strSampleSQLTableName & ";"

Set rs1 = db1.OpenRecordset(strSQL1, dbOpenDynaset)

'Connection is OK, continue
CheckSQLLinks = True

ExitOnLink:
db1.Close
Exit Function

ErrOnLink:
CheckSQLLinks = False
GoTo ExitOnLink

End Function
************************************************** *************************
Thanks,
Scott

Nov 13 '05 #2
Hi Alex,

Thanks for the reply.

I'm using Access 2003. I just tried the project in Access XP and, as you
said, it works fine. This must be a bug/feature in Access 2003.

It was suggested in another thread that I try usind ADO to test my
connection rather than DAO. Apparantly I won't encounter the problem.

Thanks,
Scott
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sean Anderson | last post by:
ODBC under System DSN Setup Access Driver give it the DSN (Data Source Name) MSA Click on Select and point to the myfile.mdb (your database file)
4
by: Andreas Lauffer | last post by:
Can anyone tell me advantages / disadvantages of DataDirect Server Wire ODBC-driver? Any experiences? What about redistribution? Andreas Lauffer, easySoft. GmbH, Germany
1
by: Lyle Fairfield | last post by:
I created a new MS-SQL Database, "TestODBC". I made Table1 and StoredProcedure1. I made an ODBC DSN for that MS-SQL Database. I created a new AccessXP mdb, "TestODBC". I linked to the...
1
by: Paul | last post by:
Hello, I am converting an Access database on our network to a sql 2000 backend and keeping access as the front end. The access database has evolved and been a solution to collect data but now...
4
by: Dave | last post by:
Hey guys, I have an ODBC problem that has me stumped. I wrote a VBA script to run in Microsoft Excel that pulls data out of an application using that application's ODBC driver and puts it into...
9
by: mcbill20 | last post by:
Hello all. I just installed Oracle 10g developer tools on a machine running XP Pro and Office XP. Before this I had just the Oracle 9 client installed. I the previous configuration, I was able to...
1
by: paul_tomlin | last post by:
We connect via terminal services to an excel spreadsheet that has an ODBC link to an access database using a pivot table, when we try to refresh the data within the excel spreadsheet we receive the...
2
by: 111mike | last post by:
Hello, Here's my problem. I cannot connect to mysql database using odbc string connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and...
0
by: PeterA | last post by:
I have a Windows PC connecting to ISeries with ODBC. The windows PC uses various SQL statements to connect to DB2 and download/upload data. Data downloads/uploads appear to be OK and I can't see...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.