Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connection String Woes
Message
From
12/08/2010 00:25:11
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01476326
Message ID:
01476327
Views:
48
>I'v got this in my app.config:
>
>
>    add name="ConnString"
>         connectionString="Data Source=MAROIS_MAIN_PC\SQLEXPRESS;Initial Catalog=AppSecurity;Trusted_Connection=Yes " 
>         providerName="System.Data.SqlClient"/
>
>
>I'm trying to read it like this:
>
>
>if (_ConnString == string.Empty)
>{
>    _ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
>}
>
>I get "Object reference not set to an instance of an object"
>
>After an hour of trying all manner of things, and no results from Google, I changed it to this:
>
> _ConnString = ConfigurationManager.ConnectionStrings[0].ConnectionString;
>
>and it return a string, but this is what gets returned
>
>
>data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
>
>
>What the hell is going on??? What's the right way to do this???

You are using an app.config, but I'm assuming your app isn't seeing it and is reading the web.config. That value that you see is the default connection string that is included in a new web.config file.
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform