HighTechTalks DotNet Forums  

Connection strings

Dotnet Framework (Webservices) microsoft.public.dotnet.framework.webservices


Discuss Connection strings in the Dotnet Framework (Webservices) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Simon
 
Posts: n/a

Default Connection strings - 12-29-2007 , 04:35 PM






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




Reply With Quote
  #2  
Old   
Steven Cheng[MSFT]
 
Posts: n/a

Default RE: Connection strings - 12-30-2007 , 09:56 PM






Hi Simon,

From your description, I understand that you're getting some problem when
try read connectionstring from configuration file of an Webservice
application ,correct?

As for the webservice application and code, would you provide some further
info? I've performed a simple test as below:

** add a connectionstring into webservice's main web.config such as
<connectionStrings>
<add name="ConnStr" connectionString="xxxxxxxxxxxxxxx"/>
</connectionStrings>

** add a webmethod which will return a certain connectionString via name.
e.g.
Quote:
[WebMethod]
public string GetConnectionString(string name)
{
return
ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
<<<<<<<<<

and I get get the connectionstring entry returned correctly. Therefore, I
wonder whether there is any particular setting difference in your
applicaiton.

Please feel free to post here if there is anything I missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
From: "Simon" <none (AT) none (DOT) com>
Subject: Connection strings
Date: Sat, 29 Dec 2007 22:35:35 +0100

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






Reply With Quote
  #3  
Old   
Simon
 
Posts: n/a

Default Re: Connection strings - 01-01-2008 , 02:58 AM



I was calling the web service incorrectly. Now everything works.

Thank you

Simon

"Steven Cheng[MSFT]" <stcheng (AT) online (DOT) microsoft.com> wrote

Quote:
Hi Simon,

From your description, I understand that you're getting some problem when
try read connectionstring from configuration file of an Webservice
application ,correct?

As for the webservice application and code, would you provide some further
info? I've performed a simple test as below:

** add a connectionstring into webservice's main web.config such as
connectionStrings
add name="ConnStr" connectionString="xxxxxxxxxxxxxxx"/
/connectionStrings

** add a webmethod which will return a certain connectionString via name.
e.g.

[WebMethod]
public string GetConnectionString(string name)
{
return
ConfigurationManager.ConnectionStrings[name].ConnectionString;
}


and I get get the connectionstring entry returned correctly. Therefore, I
wonder whether there is any particular setting difference in your
applicaiton.

Please feel free to post here if there is anything I missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.




--------------------
From: "Simon" <none (AT) none (DOT) com
Subject: Connection strings
Date: Sat, 29 Dec 2007 22:35:35 +0100

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






Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.