Question

  • Creator
    Topic
  • #2154168

    Problem with SqlConnection

    Locked

    by abezulski ·

    Hello, I have a problem with MS SQL Server SqlConnection and SqlHelper class, but I don’t have any compilation errors:

    Here is a method in my class:

    public SqlDataReader showCategories()
    {
    //string dbLink = ConfigurationManager.AppSettings[“cnstr”];
    SqlDataReader dtrCategories;
    try
    {
    dtrCategories = SqlHelper.ExecuteReader(ConfigurationManager.AppSettings[“cnstr”], CommandType.StoredProcedure, “spCategoriesShow”);
    dtrCategories.Read();

    }
    catch(Exception ex)
    {
    throw ex;

    }
    return dtrCategories;
    }

    Then I have page where I call previous method and try bind data to Repeater:

    protected void Page_Load(object sender, EventArgs e)
    {
    Categories myCat = new Categories();
    myCat.Name=”Adam”;
    lblImie.Text = myCat.Name.ToUpper();
    rptCategoriesShow.DataSource = myCat.showCategories();
    rptCategoriesShow.DataBind();
    /* SqlConnection dblink = new SqlConnection(ConfigurationManager.AppSettings[“cntstr”]);

    try
    {
    dblink.Open();
    lblImie.Text += ” Jest połączenie”;
    }
    catch (Exception ex)
    {
    lblImie.Text = ex.ToString();
    }
    finally
    {
    dblink.Close();
    }
    */
    }

    But there is something wrog: I receive error:

    Server Error in ‘/3t2’ Application.
    The ConnectionString property has not been initialized.

    Any suggestions

All Answers

Viewing 2 reply threads