Solved

ODBC Connection String

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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