Solved

ODBC Connection String

Posted on 2014-09-28
2
781 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

740 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