
Connecting to Access 97 Database using ADO with OLE DB Driver
Here is the code that I used to connect to ACCESS97 via ADO and all works
fine.
I have this code in a class named CLOGIN
------------
'----------------------------------------------------------------------
' Module Name: CLOGIN
' Author: Clint M. LaFever
'
' Description: CLOGIN Class - Interface to log into database using
' ADO 2.0
'
'----------------------------------------------------------------------
Option Explicit
Public DataBaseName As String
Public ServerName As String
Public UserName As String
Public Password As String
Public cn As ADODB.Connection
Public Enum DATABASE_TYPES
SQL_SERVER = 0
MS_ACCESS97 = 1
End Enum
Public Function ConnectRemote(Optional dbTYPE As DATABASE_TYPES = 0) As
Boolean
On Error GoTo ConnectRemote_Error
Dim sConnect As String
If dbTYPE = SQL_SERVER Then
sConnect = "DRIVER={SQL Server};SERVER=" & Me.ServerName _
& ";UID=" & Me.UserName & ";PWD=" & Me.Password & ";DATABASE=" &
Me.DataBaseName & ";"
Else
sConnect = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" &
Me.DataBaseName & ";"
End If
Set cn = New ADODB.Connection
cn.Open sConnect
If cn.State = adStateOpen Then
ConnectRemote = True
Else
ConnectRemote = False
End If
Call SaveSetting(App.Title, "Startup", "ConnectionVersion", cn.Version)
Call SaveSetting(App.Title, "Startup", "LastConnected", Now)
ConnectRemote = True
ConnectRemote_Exit:
Exit Function
ConnectRemote_Error:
Call SaveSetting(App.Title, "StartUp", "LastError", Err & ":" &
Err.Description)
ConnectRemote = False
Resume ConnectRemote_Exit
End Function
--------------
------------------------------------------
Clint M. LaFever
Lead Software Engineer
SAIC Decision Support Division
1235 Jefferson Davis Hwy, Suite 411
Arlington, VA 22202
703-413-8991 (wk)
703-413-6058 (fax)
http://www.saic.com
------------------------------------------
Quote:
>I am trying to connect to Access 97 database using ADO with Microsoft
>Jet 3.51 OLE DB Provider but I get an error that the "Test Connection
>failed because of an error in intializing provider. Can't open a
>database created with a previous version of your application.". However
>if convert the database into Access 2000 I can open it. Is there some
>other OLE DB drivers I need to get for Access 97 files.
>Any help will be appreciated.
>Thanks
>Raj