Data source name not found and no default driver specified

mrojas

Member
Joined
May 4, 2009
Messages
11
Location
Concord, Ca.
Programming Experience
5-10
I'm using VB2008 and want to connect to a Access 2007 database. I have the following code and receive the above error message when I step it through the code:
Imports Microsoft.Data.Odbc

Public Class frmODBCsample

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
On Error GoTo ErrorArea
Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TicketingSystem.mdb; Persist Security Info=False"
Dim strQuery As String = "SELECT * FROM Authors"

Dim conDB As New OdbcConnection(conStr)
conDB.Open()

Could anyone tell me what I'm missing or doing wrong?

Thanks in advance.

Milton
 
Data source name not found and no default driver specified

I've answered my own question and it migth help those facing same problem.

I needed to add the following "Imports System.Data.OleDb" outside any declaration at top of class, making sure that the System is listed in the list of .Net references for the project (Project>Add Reference>.Net tab).
I then added the following code to my routine:
Dim conStr As String
Dim condb As OleDbConnection

conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Employees.mdb"
condb = New OleDbConnection(conStr)
condb.Open()


Viola!
 
Back
Top