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;
dtrCategories = SqlHelper.ExecuteReader(ConfigurationManager.AppSettings["cnstr"], CommandType.StoredProcedure, "spCategoriesShow");

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();
lblImie.Text = myCat.Name.ToUpper();
rptCategoriesShow.DataSource = myCat.showCategories();
/* SqlConnection dblink = new SqlConnection(ConfigurationManager.AppSettings["cntstr"]);

lblImie.Text += " Jest połączenie";
catch (Exception ex)
lblImie.Text = ex.ToString();

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 -

So what is in

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


the error would suggest it's null.

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

Collapse -


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