Connection strings

Tech-Archive recommends: Fix windows errors by optimizing your registry



I have problems with connection strings. I have added new connection string to Web.config:

<connectionStrings>
<add name="ConnStr" connectionString="xxxxxxxxxxxxxxx"/>
</connectionStrings>

Bu when I want to access the data with:

coll = ConfigurationManager.ConnectionStrings;
connStr = coll[0].ConnectionString;
connStr = coll["ConnStr"].ConnectionString;

Second line returns:
"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"

And the third line return null reference exception.

Why? Is it not enough to change the connectionStrings section in project and this should work?

Thank you

Simon



.