Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / September 2007

Tip: Looking for answers? Try searching our database.

How to test connectivity with sql server 2005?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sandal - 23 Sep 2007 06:20 GMT
An access 2003 mdb uses odbc to connect with sql server 2005. Before any
operations are attempted I'd like to make sure the odbc connection is
good, ie not down due to network or server issues. Is there a simple way
to make this test? I'm using sql authentication.
Dan Guzman - 23 Sep 2007 15:05 GMT
> An access 2003 mdb uses odbc to connect with sql server 2005. Before any
> operations are attempted I'd like to make sure the odbc connection is
> good, ie not down due to network or server issues. Is there a simple way
> to make this test? I'm using sql authentication.

Below is a VBA function example that tests connectivity using ADO/ODBC.  You
can change the connection string and code according to your needs.  This
method requires a reference to the Microsoft ActiveX Data Objects Library.

Private Function GoodConnection()

   Dim connection As New ADODB.connection

   On Error GoTo Connection_Error
   connection.Open "Driver={SQL Server};" & _
       "Server=MyServer;" & _
       "Database=MyDatabase;" & _
       "Uid=MyUser;" & _
       "Password=MyPassword"
   On Error GoTo 0

   connection.Close
   Set connection = Nothing

   GoodConnection = True
   Exit Function

Connection_Error:

   Dim strErrorMessages As String
   Dim Error As ADODB.Error

   For Each Error In connection.Errors
       strErrorMessages = strErrorMessages & Error.Description & vbCrLf
   Next Error

   MsgBox "Unable to connection to SQL Server: " & strErrorMessages
   Set connection = Nothing

   GoodConnection = False

End Function

Signature

Hope this helps.

Dan Guzman
SQL Server MVP

> An access 2003 mdb uses odbc to connect with sql server 2005. Before any
> operations are attempted I'd like to make sure the odbc connection is
> good, ie not down due to network or server issues. Is there a simple way
> to make this test? I'm using sql authentication.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.