Question

Locked

Problem with SqlConnection

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

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Go here for more info...

http://www.pythian.com/blogs/1114/mysql-back-to-basics-analyze-check-optimize-and-repair

Please post back if you have any more problems or questions.

Collapse -

So what is in

by Tony Hopkinson In reply to Problem with SqlConnectio ...

ConfigurationManager.AppSettings["cnstr"]

the error would suggest it's null.

I not in somesplaces in the code you have cntstr ....

Collapse -

Fixed!

by abezulski In reply to So what is in

That's it! I made spelling mistake. Thanks! I don't know how could i miss that.

Collapse -

All too easy I'm afraid

by Tony Hopkinson In reply to Fixed!

Craete a constant for the string literal some place, then at least they'l all be spelled the same though not necessarily correctly.

Back to Windows Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums