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
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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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