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

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

... 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)

... 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:
    <add name="objConnCHNET" connectionString="Dsn=CHNET;uid=Admin" providerName="System.Data.Odbc" />

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

    Accepted Solution

    You are using an ODBC connection string, so you should be using an OdbcConnection and not an OleDbConnection.


    Author Comment

    Once again Bob - thank you for your quick response and solution.


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Read about why website design really matters in today's demanding market.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    730 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

    16 Experts available now in Live!

    Get 1:1 Help Now