Problem with SqlConnection - TechRepublic
Question
August 2, 2008 at 08:17 AM
abezulski

Problem with SqlConnection

by abezulski . Updated 17 years, 11 months ago

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

This discussion is locked

All Comments