Search This Blog

Loading...

Thursday, May 15, 2008

Null Reference Exception in System.Configuration.ConfigurationManager.ConnectionStrings

You may get this when you are running your tests against a database application: .a null reference exception in accessing System.Configuration.ConfigurationManager.ConnectionStrings["BlahBlah"] property. You check your configuration file in your application, the connection string "BlahBlah"is there. And if you press F5 to run the application in the normal way, there is no such exception at all.

I got this when I was trying out ScotGu's ASP.NET MVC tutorial, when I ran the very first unit test example.

The solution? Easy, just to create an App.Config file for your test project ( not your application project) and put in the above connection string. In this way the test project will know where to find the "BlahBlah" connection string and make the proper connection.

10 comments:

Anonymous said...

Thanks dear.

elsurexiste said...

You are a lifesaver!

Anonymous said...

haha, wow... DUH!!! thanks!

Lucas PĂ©rez said...

I'm sorry but i don't understand what you mean, i'm a litle newbie i think..
I have 2 projects, and two configuration files

can you explain your solutions more specifically plz?

Andy said...

Thank you, I've been frustrated over this all day.

Anonymous said...

Yep... Thanks!

patrick said...

Great, thanks! You just saved my life!

masudio said...

YEAH!

Anonymous said...

YEAH! So simple.

sql said...

Thank you so much!!