Connection String Runtime Exception

Posted by Kundnani.rt under ASP.NET on 1/2/2012 | Points: 10 | Views : 1331 | Status : [Member] | Replies : 6
I m getting runtime problem in this line..... of my Code
----------------------------------------------------------------------------------------------------------------------------
string _connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
----------------------------------------------------------------------------------------------------------------------------

Please help me to solve it...

Here is my entire code file....




Responses

Posted by: SheoNarayan on: 1/2/2012 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
There is hardly any reason of getting runtime error if you have the reference of the namespace kept properly on the page.

ConfigurationManager class needs System.Configuration namespace referenced into your project and added into the using statement at the top of the class. Just try these in case you have not done already and it should.

After trying above, still if doesn't work, copy-paste the complete error you are getting and we shall try to sort it out.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Kundnani.rt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naimishforu on: 1/3/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Are you missing .ToString()??

Not sure if it requires to use....

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Kundnani.rt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 1/3/2012 [Member] [MVP] Starter | Points: 25

Up
0
Down
hi,
use culture... and add namspaces .. using System.Configuration;

string constr1;
IFormatProvider culture = new CultureInfo("fr-Fr", true);
constr1 = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

it's working.... try it ...


Best Regard's
Prabhakar

Kundnani.rt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundnani.rt on: 1/3/2012 [Member] Starter | Points: 25

Up
0
Down
Its not working its giving error on "CultureInfo("fr-Fr", true)"

Kundnani.rt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundnani.rt on: 1/3/2012 [Member] Starter | Points: 25

Up
0
Down
My Code contains this foll. line:
-----------------------------------------------------------------------------------------------------------------------------------------
string _connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString.ToString();
-----------------------------------------------------------------------------------------------------------------------------------------


At Runtime I m getting NullReferenceException , and error is

"NullReferenceException was unhandled by user code"

Kundnani.rt, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 1/4/2012 [Member] Starter | Points: 25

Up
0
Down
have you checked whether "ConnStr" exist in web.config file??

Kind Regards,
Jay

Kundnani.rt, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response