?
Solved

How do I get a valid Access database connection string from my web.config file?

Posted on 2007-07-31
2
Medium Priority
?
200 Views
Last Modified: 2012-06-21
The following code works:
        Dim objCS As String
        objCS = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\webspace\ClevelandHall.org.uk\db\CHNET.mdb"
        Dim objConnCHNET As OleDbConnection = New OleDbConnection(objCS)
        objConnCHNET.Open()

... but I do not really want to have the datasource hard-coded like this as I am trying to build a generic solution and would prefer to get the connection string info from the web.config file, like this:

        Dim objCS As String
        objCS = ConfigurationManager.ConnectionStrings("objConnCHNET").ConnectionString
        Dim objConnCHNET As OleDbConnection = New OleDbConnection(objCS)
        objConnCHNET.Open()

... however, running this code results in the error "An OLE DB Provider was not specified in the ConnectionString".

My web.config entries are as follows:
  <connectionStrings>
    <add name="objConnCHNET" connectionString="Dsn=CHNET;uid=Admin" providerName="System.Data.Odbc" />
  </connectionStrings>

Question: How do I build a valid connection string in code behind from the data contained in web.config connectionStrings?
0
Comment
Question by:SRalling
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 19602118
You are using an ODBC connection string, so you should be using an OdbcConnection and not an OleDbConnection.

Bob
0
 

Author Comment

by:SRalling
ID: 19602224
Once again Bob - thank you for your quick response and solution.

Steve
0

Featured Post

Industry Leaders: 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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

757 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