Solved

Set sqldatasource at run time

Posted on 2016-08-04
2
34 Views
Last Modified: 2016-08-04
The below asp code sets an sqldatasource.  
I want the the program to look at C:\InetPub\wwwroot\web.config and set the connection string based upon what it finds there.  In other words the parameter ConnectionStrings:DS2DSSQLConnStr won't be set until the program has checked C:\InetPub\wwwroot\web.config

What's the best way to do this?

<asp:SqlDataSource ID="sdsSchemas" runat="server" ConnectionString="<%$ ConnectionStrings:DS2DSSQLConnStr %>"
        SelectCommand="RO_SelectEquityCSchema" SelectCommandType="StoredProcedure" 
        UpdateCommand="RO_UpdateCSchema" UpdateCommandType="StoredProcedure">
        <SelectParameters>
            <asp:SessionParameter Name="rtrExchangeCode" SessionField="RTRExch" />
            <asp:SessionParameter Name="rtrInstrumentTypeCode" SessionField="RTRitc" />            
        </SelectParameters>        
        <UpdateParameters>
            <asp:Parameter Name="FileNameCode" Type="String" />
            <asp:Parameter Name="Required" Type="String" />
            <asp:Parameter Name="rc" Type="int16" Direction="output" />
        </UpdateParameters>
    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:AlHal2
2 Comments
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41742361
[VB] System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionStringName").ConnectionString
[C#] System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString
string connection ;
connection = configurationManager.connectionstring("MyConnectionString").connectionstrings;
sqlconnection conn = new sqlconnection (connection);
conn.open ();

Open in new window

web.config
<connectionStrings>
        <add name="MyConnectionString" connectionString="Data Source=SERV002;Initial Catalog=Training;Persist Security Info=True;User ID=Test;Password=Test" providerName="System.Data.SqlClient"/>
    </connectionStrings>

Open in new window

0
 

Author Closing Comment

by:AlHal2
ID: 41742515
Thanks.  I simply moved the connection string from web.config for this program to C:\inetpub\wwwroot\web.config.
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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

11 Experts available now in Live!

Get 1:1 Help Now