The ConnectionString property has not been initialized. PLEASE HELP

  • 9 years ago

    Hi,

    Im trying to connect to a stored procedure.  When I build the project, it succeeds but once I dubug it, the error above appears.  My code is below. I am new at this so bear with me. The error is coming from adpater.Fill(ds,"tbl_DoctorsOrders")

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Text;

    using System.Web;

    using System.Web.UI.WebControls;

    using System.Web.UI.Design;

    using System.Data;

    using System.Data.SqlClient;

    using System.Configuration;

    public partial class PDFViewer : System.Web.UI.Page

    {

    protected void Save_Click(object sender, EventArgs e)

    {

    SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

    SqlCommand myCmd = new SqlCommand("dbo.GetPDFDocument", myConn);

    myCmd.CommandType = CommandType.StoredProcedure;

    SqlDataAdapter adapter = new SqlDataAdapter(myCmd);

    DataSet ds = new DataSet();

    adapter.Fill(ds,"tbl_DoctorsOrders");

    this.DetailsView1.DataSource = ds;

    this.DetailsView1.DataMember = "tbl_DoctorsOrder";

  • 9 years ago

    You need to open the connection.

    SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

    SqlCommand myCmd = new SqlCommand("dbo.GetPDFDocument", myConn);

    myCmd.CommandType = CommandType.StoredProcedure;

    myCmd.Connection.Open(); 

    .

    .

    myCmd.Connection.Close();

    (google for the "using" statement - auto close's the connection for you).

    Joe
     


     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”