Solved

ODBC Connection String

Posted on 2014-09-28
2
759 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now