HELP :: Set Connection String Dynamicly in App.Config

Last post 07-06-2009 2:01 AM by vora_bhaumik. 1 replies.

Sort Posts:

  • HELP :: Set Connection String Dynamicly in App.Config

    07-05-2009, 5:13 AM
    • Member
      78 point Member
    • farhad_m
    • Member since 05-17-2009, 5:56 AM
    • Tehran, Iran
    • Posts 25

     Hello guys,

    How can I set connection string dynamicly in App.Config file?

    I want to use the dynamic connection string in DataSet

    If you get the correct answer, please just click Mark As Answer and set your post to Resolved.

    Best Regards
    Farhad Mahmoudvand


  • Re: HELP :: Set Connection String Dynamicly in App.Config

    07-06-2009, 2:01 AM
    Answer
    • Contributor
      2,042 point Contributor
    • vora_bhaumik
    • Member since 11-25-2008, 10:56 PM
    • Ahmedabad
    • Posts 339

    Hi,

    U can also go through this link and also try the following code.

    http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/f44516e2-36c3-45dd-8318-fcdf4a8113b9/


    Code:-


    <appsettings>
    <add key="production" value="http://www.production.com">
    <add key="ProductionconnectionString" value="server=localhost;...." >
    <add key="testconnectionString" value="server=localhost;...." >
    </appsettings>
    Public Application_BeginRequest()
    {
    bool production=false;
    if(Request.URL.Host==ConfiqurationManager.Appsettings("production"))
    {
    Production=true;
    }
    }

    if(Production==true)
    {
    context.items.add("connectionStrings",ConfiqurationManager.Appsettings("production"))
    }
    else
    {
    context.items.add("connectionStrings",ConfiqurationManager.Appsettings("test"))
    }
    }


    Enjoy Smile

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.

    Regards,
    Bhaumik
Page 1 of 1 (2 items)