473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Connection strings

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

Dec 29 '07 #1
2 1742
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" <no**@none.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


Dec 31 '07 #2
I was calling the web service incorrectly. Now everything works.

Thank you

Simon

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:MM**************@TK2MSFTNGHUB02.phx.gbl...
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" <no**@none.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

Jan 1 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JWM | last post by:
I am trying to implement Oracle connection pooling for the following code, which was written by someone else. Here is my main question -- this java file creates code that is executed every hour,...
4
by: Matthew Wells | last post by:
FIRST OF ALL, I APPRECIATE PEOPLE SENDIUNG ME LINKS TO WEB SITES FOR CONNECTION STRINGS BUT AS I'VE SAID BEFORE THAT IS NOT WHAT I NEED. I CAN EASILY OPEN AN ADO CONNECTION OBJECT TO AS400. I...
1
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
7
by: Gary Brizard | last post by:
OK. For an n-tier architecture, where is the best place to store the connection string for the DA layer? I don't want to use the reg. Can't use a app.config for a dll. For other projects I...
14
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
5
by: Matt | last post by:
Hello, What is the best way to handle the database connection string for a class library project that will be compiled and used as a .dll? This .dll will be accessed via classic ASP and in...
3
by: Harry Strybos | last post by:
Hi All I have a really strange problem occurring in my application. When I read in the application settings for connection strings the following happens: Here are my connection string settings...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
2
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.