.net strongly typed dataset and connection string at runtime

Posted on 2009-02-24
Last Modified: 2013-12-17
I have a stronly typed dataset in a dll.  It currently has a hard coded connection string.  The same dll also has a class I call ApplicationSettings which loads app setting from a config file located on the network.

How can I make my dataset get it's connection string at runtime.  Is there an event for the DS?  
Question by:jackjohnson44
    LVL 41

    Accepted Solution

    This is a bit complicated, so bare with me...  
    Yes, you can (and should) move your hard-coded connection string to the "app.config" file.   However, there is a catch... the designer will put the connection string in the wrong "app.config" file.   It will put it in the app.config file for the DLL (which is totally useless, the DLL files don't look there)
    The solution is that you let the designer put the file in the wrong place... then just use Notepad to copy the few lines of XML code from the DLL's config file to paste it into the app.config file of the application (the *.exe file) that consumes the DLL.
    Using this technique your Application will load the DLL, and the DLL will be able to use the ApplicationSetting sections of the Application's config file.

    Author Comment

    Thanks, but isn't there an easier way by overriding functions on the dataset?

    I have clicked by accident before and saw a class with code behind.
    I just can't figure out how to do it.
    LVL 41

    Expert Comment

    Well, sure... a "write your own" is always an option.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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.

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 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

    10 Experts available now in Live!

    Get 1:1 Help Now