Groups | Blog | Home
all groups > dotnet web services > december 2007 >

dotnet web services : Connection strings?


Simon
12/29/2007 10:30:10 PM
I have created new web service and inserted connection strings to web.config
file:

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

When I try to read this connection string:

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

coll has only one member and that one has ConnectionString value:
"data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true"

If I try to read the "ConnStr" value I get null reference exception.

Why is that? Is it not enough to change the Web.config file in project and
that should work?

Thank you

Simon
stcheng@online.microsoft.com
12/31/2007 2:59:04 AM
Hi Simon,

I have seen your another thread on this issue in the same newsgroup. I've
replied you there. Welcome to followup and continue to discuss in that
thread.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Simon" <none@none.com>
Subject: Connection strings?
Date: Sat, 29 Dec 2007 22:30:10 +010

I have created new web service and inserted connection strings to
web.config
file:

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

When I try to read this connection string:

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

coll has only one member and that one has ConnectionString value:
"data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true"

If I try to read the "ConnStr" value I get null reference exception.

Why is that? Is it not enough to change the Web.config file in project and
that should work?

Thank you

AddThis Social Bookmark Button