Discussion Locked

How to connect a database?

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

In the Control Panel under Administrative Tools in Windows 2000, Data Sources (ODBC) how do I connect my Microsoft Access database? Also in VB 6.0 in my Module how do I code the connection? I know how in Windows 98 and using ADODB. See below.Public Sub open_access()

Set Delaine= New ADODB.Connection

Delaine.Provider = "Microsoft OLE DB Provider.ODBC;Persist Security Info=False;"
Delaine.ConnectionString = "Data Source = " & App.Path & "\CricketWorks.mdb"

End Sub

Please help me.

3 replies

by andrew

The Data Sources (ODBC) utility is used to create DSNs for you to access databases. You need create an ODBC DSN that points to your Access DB.

On the 'System DSN' tab, click on the 'Add' button and select the Microsoft Access Driver (*.mdb), thenclick 'Finish'

On the next dialog, name the DSN (let's call it 'AccessTest') and click on 'Select' and browse to the MDB file. If you need security, enter the credentials in the 'Advanced' dialog. Click 'OK'.

In VB, you can use just the DSN asa connection string:

Dim oCon as ADODB.Connection
Set oCon = New ADODB.Connection
oCon.Open "AccessTest"

Now that I've told you all this, I recommend you don't use it. Just use a pure OLEDB connection (DSN-less):

Dim oCon As ADODB.Connection
Set oCon = New ADODB.Connection
oCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DBFileName.mdb;"

This will be much faster, and you don't have to mess with ODBC.

This discussion is closed to new replies.