ASP.NET ConnectionString not working

Posted on 2011-09-05
Last Modified: 2012-05-12
In my .aspx page VS2008 C# ASP.NET I have this line:
<asp:SqlDataSource ID="mySqlDataSourceID" runat="server"
                                ConnectionString="<%$ ConnectionStrings:myConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:myConnectionString1.ProviderName %>"
        SelectCommand="SELECT * from MyTab">
The web.config has:
    <add name="myConnectionString1" connectionString="DATA SOURCE=mySOMETHING1;PASSWORD=myPwd;PERSIST SECURITY INFO=True;USER ID=myID"
     providerName="Oracle.DataAccess.Client" />
Above works.

But I need to get rid of "myConnectionString1" under   <connectionStrings> in the web.config file.
Instead I need to use the similar stuf under: <appSettings> in the web.config file.

The current contenct in web.config ther is:
<add key="myKey1" value="Data Source=mySOMETHING1;Persist Security Info=True;User ID=myID;Password=myPwd;"/>

The value of "myKey1" in the   <appSettings> is same as the myConnectionString1under  <myConnectionString>.

How could I use "myKey1" of   <appSettings> above instead of "myConnectionString1" in   <connectionStrings> for the SqlDataSource ID "mySqlDataSourceID" ?
In my

I tried:
<asp:SqlDataSource ID="mySqlDataSourceID" runat="server"
                                ConnectionString="<%$ AppSettings["myKey1"] %>"
        SelectCommand="SELECT * from MyTab">

But It shows syntax error for the line:
                                ConnectionString="<%$ AppSettings["myKey1"] %>"

How to fix?
Question by:toooki
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36486792
"<%$ AppSettings.Settings["myKey1"] %>"
LVL 25

Accepted Solution

Luis Pérez earned 238 total points
ID: 36486823
"<%$ AppSettings:myKey1 %>"

Assisted Solution

AnuTiji earned 237 total points
ID: 36486851
Please try the following code
 <asp:SqlDataSource ID="mySqlDataSourceID" runat="server" ConnectionString="<%$ appSettings:myKey1 %>"  ProviderName=System.Data.OracleClient
              SelectCommand="SELECT * from MyTab">

Open in new window


Author Comment

ID: 36583992
Thank you. I am going to try.

Author Comment

ID: 37129393
Thank you all. It worked.

This syntax worked:

<asp:SqlDataSource ID="mySqlDataSourceID" runat="server"
                               ConnectionString="<%$ appSettings:myKey1 %>"

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace &lt; with < 14 55
Counting connections to SQL Server through C# 3 28
Video Player 2017 5 8
C# guarantee sql connection close 6 13
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (, 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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

24 Experts available now in Live!

Get 1:1 Help Now