Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set sqldatasource at run time

Posted on 2016-08-04
2
Medium Priority
?
69 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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