views:

724

answers:

2

OK so I one page I find this line:

objDsCourse = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings("connstr").ConnectionString, CommandType.StoredProcedure, "Course_NewReportGet_Get_Sav", objPAra)

And I copied it to another page to start modifying it to work there:

getData = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings("connstr").ConnectionString, CommandType.StoredProcedure, "Course_NewReportGet_Get_Sav", objPAra)

However on the new page it underlines .ConnectionStrings saying that Non-invocable member 'System.Configuration.ConfigurationManager.ConnectionStrings' cannot be used like a method'... then why did it work in the other page??

EDIT: OK so I found in web.config what I think it is referencing because it says

<add name="ConnStr" connectionString="data source=..." />

Why would one page have access to this and the other not?

+2  A: 

Is there any chance one page is using VB.NET, while the other is using C#?

Daniel Pratt
YES! That is exactly true. I must be using it wrong then... brackets instead?
shogun
brackets instead of parenthesis seems to have fixed it, thanks for the tip *smacks forehead*
shogun
A: 

I would agree with Daniel. In Visual Basic, both dictionary objects and methods are referenced by using parentheses. This can cause some confusion.

So in VB, ConfigurationManager.ConnectionStrings("connstr") would point to the ConnectionString object with the key "connstr" in the dictionary.

In C#, dictionary objects are referenced by square brackets [] so ConfigurationManager.ConnectionStrings("connstr") would literally mean "invoke the method ConnectionStrings of ConfigurationManager object using "connstr" as a parameter."

Long story short, check the <%@ Page %> declaration at the top to make sure both pages are the same language. ... or, on the page with the error, change the line to use the ConfigurationManager.ConnectionStrings["connstr"] syntax.

Matt Murrell