Solved

ODBC Connection String

Posted on 2014-09-28
2
774 Views
Last Modified: 2014-09-28
I am trying to connect to an MS Access 2013 database using the following code.  Why does this not work???

New OleDbConnection(String.Format("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq={0}; Uid=admin; Pwd=;", inAccessDBName))

Can you correct this?
0
Comment
Question by:Ray Turner
2 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 40349249
You either need to use an ODBCConnection class or use the the correct provider for OleDB connection. In case of the former, the connection string will be:
New OdbcConnection(String.Format("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq={0}; Uid=admin; Pwd=;", inAccessDBName))

Open in new window

If you use the OleDB connection you need to specify the "Microsoft OLE DB Provider for ODBC Drivers" (MSDASQL.1). The complete connection string will be:
New OleDbConnection(String.Format("Provider=MSDASQL.1;Extended Properties=""Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=c:\test.mdb; Uid=admin; Pwd=;"""", inAccessDBName"))

Open in new window

Please note that you must use double quotes in the connection string.
BTW, the best way to test (and create) OLE DB connection strings is by using a UDL trick. Create an empty text file with UDL extension. Open it. Select a provider on the first tab page and select extended options on the second. Press OK. The file will be saved. Open it with Notepad. The connection string will be inside the file. You can then delete the file
0
 

Author Comment

by:Ray Turner
ID: 40349265
Thanks!  This is what I needed.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question