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

x
?
Solved

ASP.NET ConnectionString not working

Posted on 2011-09-05
5
Medium Priority
?
397 Views
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 %>"
                                onselecting="mysomething"                                
ProviderName="<%$ ConnectionStrings:myConnectionString1.ProviderName %>"
        SelectCommand="SELECT * from MyTab">
</asp:SqlDataSource>
-----------
The web.config has:
<configuration>
  <connectionStrings>
    <add name="myConnectionString1" connectionString="DATA SOURCE=mySOMETHING1;PASSWORD=myPwd;PERSIST SECURITY INFO=True;USER ID=myID"
     providerName="Oracle.DataAccess.Client" />
  </connectionStrings>
</configuration>
------
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:
  <appSettings>
<add key="myKey1" value="Data Source=mySOMETHING1;Persist Security Info=True;User ID=myID;Password=myPwd;"/>
</appSettings>

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 .aspx.page?

I tried:
<asp:SqlDataSource ID="mySqlDataSourceID" runat="server"
                                ConnectionString="<%$ AppSettings["myKey1"] %>"
                                onselecting="mysomething"                                
ProviderName="Oracle.DataAccess.Client"
        SelectCommand="SELECT * from MyTab">
</asp:SqlDataSource>

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

How to fix?
0
Comment
Question by:toooki
[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
5 Comments
 
LVL 16

Expert Comment

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

Accepted Solution

by:
Luis Pérez earned 952 total points
ID: 36486823
"<%$ AppSettings:myKey1 %>"
0
 
LVL 4

Assisted Solution

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

Open in new window

0
 

Author Comment

by:toooki
ID: 36583992
Thank you. I am going to try.
0
 

Author Comment

by:toooki
ID: 37129393
Thank you all. It worked.

This syntax worked:

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

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