Solved

ODBC Connection String

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

705 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

18 Experts available now in Live!

Get 1:1 Help Now