Solved

Set sqldatasource at run time

Posted on 2016-08-04
2
56 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 81

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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