How to specify connection string from web.config inside the SqlDataSource

Posted on 2009-12-22
Last Modified: 2013-11-07
I have a connection string specified in my web.config file

      <add name="conn" connectionString="my string here" />

and here is my SqlDataSource:

 <asp:SqlDataSource ID="sds1" runat="server" ConnectionString ="<%$ ConnectionStrings:conn" %>" SelectCommand="SELECT Field1 FROM Table1"></asp:SqlDataSource>

I keep getting 2 errors:

1)The server tag is not well formed


2)Literal expressions like '<%$ ConnectionStrings:conn" %>' are not allowed. Use <asp:Literal runat="server" Text="<%$ ConnectionStrings:conn"%>" /> instead.      

What am I doing wrong?
Question by:YZlat
    LVL 8

    Expert Comment

    by:deepu chandran
    LVL 3

    Accepted Solution

    Instead of:
    ConnectionString ="<%$ ConnectionStrings:conn" %>"

    ConnectionString ="<%$ ConnectionStrings:conn %>"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    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…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now