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


ASP.NET ConnectionString not working

Posted on 2011-09-05
Medium Priority
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 952 total points
ID: 36486823
"<%$ AppSettings:myKey1 %>"

Assisted Solution

AnuTiji earned 948 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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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