>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.