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

  • Home
  • SEARCH
  • 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 4109810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:51:00+00:00 2026-05-20T21:51:00+00:00

I have a C# ASP.NET web application an I am trying to populate an

  • 0

I have a C# ASP.NET web application an I am trying to populate an ASP:DropDownList with a column in a database table.

My Code:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Configuration;

namespace CRM2Sage
{
    public partial class SOPOrderEntry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Fill1();
        }

        public void Fill1()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM Products", new SqlConnection(WebConfigurationManager.AppSettings["CRM2Sage"]));
            //cmd.Connection.Open();
            cmd.Connection.Open();

            SqlDataReader ddlValues;
            ddlValues = cmd.ExecuteReader();

            vproduct.DataSource = ddlValues;
            vproduct.DataValueField = "theName";
            vproduct.DataTextField = "theName";
            vproduct.DataBind();

            cmd.Connection.Close();
            cmd.Connection.Dispose();
        }
    }
}

An when I run the page I get the following error

The ConnectionString property has
not been initialized.

pointing to cmd.Connection.Open(); I can not understand why, the SQL connection is stored in my web.config file.

The web.config

<?xml version="1.0"?>
<configuration>

    <appSettings />
    <connectionStrings>
      <add name="CRM2Sage" connectionString="Data Source=W2003CRMDEMO; Initial Catalog=CRM2Sage; User ID=newSA; Password=password;" providerName="System.Data.SqlClient" />
    </connectionStrings>

    <system.web>
        <compilation debug="true">

        </compilation>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="Windows" />
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>

Can anyone help?

Cheers

Justin

  • 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-20T21:51:00+00:00Added an answer on May 20, 2026 at 9:51 pm

    You need to retrieve the .ConnectionString property :

    string connectionString = WebConfigurationManager.ConnectionStrings["CRM2Sage"].ConnectionString;
    
    using(SqlConnection _con = new SqlConnection(connectionString))
    using(SqlCommand cmd = new SqlCommand("SELECT * FROM Products", _con))
    {
       // do your stuff here
    }
    

    What you’re doing right now is just retrieving the whole entry under <connectionStrings> by the name of CRM2Sage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have VS2005 and I am currently trying to debug an ASP.net web application.
I'm designing my database and LINQ To SQL ASP.NET web application. Imagine I have
So I have an asp.net Web Application (Not Web Site) that I am trying
Basically what I'm trying to do is, I have an ASP.Net web application that's
Here's what I'm trying to do. I have an ASP.NET MVC web application, where
I have an ASP.Net Web Forms application in which I'm using forms-based authentication with
I have a asp.net web application which has a number of versions deployed on
I have an ASP.NET web application which does the following: Reads an Excel file.
We have an intranet asp.net web application which uses the OOTB ASP.net membership and
Suppose you have two seperate ASP.NET Web Application projects that both need to use

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.