sql server - C# SqlCommand Connection.Open() issue -


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

My code:

  Using the 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 SOPOrderEntry: System.Web.UI.Page {Secure Zero Page_load (Object Sender, EventArgs e) {Fill1 (); } Public Zero 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 (); }}}   

When I run the page, I get the following error

ConnectionString property has not been started.

indicating cmd.Connection.Open (); I do not understand why, SQL Connection is stored in my web.config file.

Web.config

  & lt ;? XML version = "1.0"? & Gt; & Lt; Configuration & gt; & Lt; App Settings / & gt; & Lt; ConnectionStrings & gt; & Lt; Add name = "CRM2Sage" connectionString = "data source = W2003CRMDEMO; initial catalog = CRM2 session; user id = newsa; password = password;" Provider Name = "System.Data.SqlClient" /> & Lt; / ConnectionStrings & gt; & Lt; System.web & gt; & Lt; Compilation debug = "true" & gt; & Lt; / Compilation & gt; & Lt ;! - & lt; Authentication & gt; The section enables the configuration of the security authentication mode used by ASP.NET to identify the incoming user. - & gt; & Lt; Authentication mode = "Windows" /> & Lt ;! - & lt; CustomArwers & gt; In the section, the configuration allows what to do if / when an uncontrolled error occurs during the execution of a request. Specifically, it enables developers to configure HTML error pages to display in place of error stack traces. & Lt; CustomError mode = "RemoteOnly" default redirect = "Generic ARRPG HTM" & gt; & Lt; Error status code = "403" redirect = "NoAccess HTM" /> & Lt; Error status code = "404" redirect = "file notoftHTML" /> & Lt; / CustomErrors & gt; - & gt; & Lt; /system.web> & Lt; / Configuration & gt;   

Can anyone help?

Cheers

Justin

you again Need to get. Connection string property:

  string connection string = web configuration manager. Connection strings ["CRM 2 SEAGE"]. (SqlConnection _con = New SqlConnection (connectionString)) (SqlCommand CMD = New SqlCommand ("SELECT * FROM PRODUCTS", _con)) {// your stuff here}   

You are just fixing, just & lt; Retrieving the entire entry in the name of the connection marks> under the name of CRM2Sage .

Comments