Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3277596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:23:12+00:00 2026-05-17T19:23:12+00:00

I have the correct entries in the web.config file in my ASP.NET project. How

  • 0

I have the correct entries in the web.config file in my ASP.NET project. How do I make sure that the connection has been established successfully? I want to pull an image form my database and then display it on my aspx page. Some things to note: I am using Visual Studio 2010, SQL server 2008, .NET 4.0
Here is the relevant part from my web.config file

<databases>    
    <add key="MyConnection" name="MyName" value="server=servername\SQL2008;uid=myuid;pwd=mypwd;database=databaseName;"/>  
    <add key="DataAccessClass" value="DataAccessSql"/>  
</databases> 

I do not have any app.config file in my project yet. Surprisingly there is not section in my web.config. Do I need to add one explicitly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:23:13+00:00Added an answer on May 17, 2026 at 7:23 pm

    The connection parameters entered in the web.config file are just parameters. No actual connections are made. In fact, multiple connection parameters can be made in the web.config and the actual connection can be made at runtime.

    To actually make a connection happen, you need to define

    For instance, here the SQLDataSource is set to connect to ConnectionStrings.MyNorthwind

    <html xmlns="http://www.w3.org/1999/xhtml" >
      <head runat="server">
        <title>ASP.NET Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
          <asp:SqlDataSource
              id="SqlDataSource1"
              runat="server"
              DataSourceMode="DataReader"
              ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
              SelectCommand="SELECT LastName FROM Employees">
          </asp:SqlDataSource>
    
          <asp:ListBox
              id="ListBox1"
              runat="server"
              DataTextField="LastName"
              DataSourceID="SqlDataSource1">
          </asp:ListBox>
    
        </form>
      </body>
    </html>
    

    or in this second example, where they explicitely create an SqlConnection. The connectionstring here would be taken from the web.config.

    private static void ReadOrderData(string connectionString)
    {
        string queryString = 
            "SELECT OrderID, CustomerID FROM dbo.Orders;";
        using (SqlConnection connection = new SqlConnection(
                   connectionString))
        {
            SqlCommand command = new SqlCommand(
                queryString, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            try
            {
                while (reader.Read())
                {
                    Console.WriteLine(String.Format("{0}, {1}",
                        reader[0], reader[1]));
                }
            }
            finally
            {
                // Always call Close when done reading.
                reader.Close();
            }
        }
    }
    

    Here is an example of a connection string to be found in your web.config

    <configuration>
      <connectionStrings>
        <add name="ApplicationServices"
             connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
             providerName="System.Data.SqlClient" />
      </connectionStrings>
    </configuration>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that has a set of entries like this: <attr
I have to correct an existing C file which has a bunch of format
I am a brand new Java developer (I have been working in asp.net) and
While uploading my current project to our staging server I noticed that the Web.config
I have the following thread code which executes correct first time. After that from
ASP.NET Login control is very slow making the initial connection to AD when authenticating
I'm trying to setup Forms Authentication in an asp.net mvc 2 application that will
The web application that I am developing right now has something called quiz engine
ASP.Net MVC 3, Kendo UI Web. Typical example -- there is a database and
I have an angularjs web app which has a view with the following basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.