473,785 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection strings

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

<connectionStri ngs>
<add name="ConnStr" connectionStrin g="xxxxxxxxxxxx xxx"/>
</connectionStrin gs>

Bu when I want to access the data with:

coll = ConfigurationMa nager.Connectio nStrings;
connStr = coll[0].ConnectionStri ng;
connStr = coll["ConnStr"].ConnectionStri ng;

Second line returns:
"data source=.\SQLEXP RESS;Integrated
Security=SSPI;A ttachDBFilename =|DataDirectory |aspnetdb.mdf;U ser
Instance=true"

And the third line return null reference exception.

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

Thank you

Simon

Dec 29 '07 #1
2 1768
Hi Simon,

From your description, I understand that you're getting some problem when
try read connectionstrin g 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 connectionstrin g into webservice's main web.config such as
<connectionStri ngs>
<add name="ConnStr" connectionStrin g="xxxxxxxxxxxx xxx"/>
</connectionStrin gs>

** add a webmethod which will return a certain connectionStrin g via name.
e.g.
>>>>>>>>>>>
[WebMethod]
public string GetConnectionSt ring(string name)
{
return
ConfigurationMa nager.Connectio nStrings[name].ConnectionStri ng;
}
<<<<<<<<<

and I get get the connectionstrin g 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.co m>
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:

<connectionStri ngs>
<add name="ConnStr" connectionStrin g="xxxxxxxxxxxx xxx"/>
</connectionStrin gs>

Bu when I want to access the data with:

coll = ConfigurationMa nager.Connectio nStrings;
connStr = coll[0].ConnectionStri ng;
connStr = coll["ConnStr"].ConnectionStri ng;

Second line returns:
"data source=.\SQLEXP RESS;Integrated
Security=SSPI;A ttachDBFilename =|DataDirectory |aspnetdb.mdf;U ser
Instance=true"

And the third line return null reference exception.

Why? Is it not enough to change the connectionStrin gs 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.comw rote in message
news:MM******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Simon,

From your description, I understand that you're getting some problem when
try read connectionstrin g 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 connectionstrin g into webservice's main web.config such as
<connectionStri ngs>
<add name="ConnStr" connectionStrin g="xxxxxxxxxxxx xxx"/>
</connectionStrin gs>

** add a webmethod which will return a certain connectionStrin g via name.
e.g.
>>>>>>>>>>>>
[WebMethod]
public string GetConnectionSt ring(string name)
{
return
ConfigurationMa nager.Connectio nStrings[name].ConnectionStri ng;
}
<<<<<<<<<

and I get get the connectionstrin g 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.co m>
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:

<connectionStri ngs>
<add name="ConnStr" connectionStrin g="xxxxxxxxxxxx xxx"/>
</connectionStrin gs>

Bu when I want to access the data with:

coll = ConfigurationMa nager.Connectio nStrings;
connStr = coll[0].ConnectionStri ng;
connStr = coll["ConnStr"].ConnectionStri ng;

Second line returns:
"data source=.\SQLEXP RESS;Integrated
Security=SSPI;A ttachDBFilename =|DataDirectory |aspnetdb.mdf;U ser
Instance=true"

And the third line return null reference exception.

Why? Is it not enough to change the connectionStrin gs 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
4748
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, but once per week, the oracle server is brought down for backup. At that time, I get an error that looks like I have the wrong credentials for the database. For every subsequent attempt to run the hourly process, I am getting a broken pipe error,...
4
5103
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 NEED TO REFRESH A DAO (Access) TABLEDEF OBJECT'S CONNECTION STRING WHICH MUST INCLUDE A CLAUSE FOR THE TABLE NAME. THIS IS WHAT I NEED. PLEASE READ AGAIN. Can someonne please tell me an ADO connection string to use to link an AS400 table to...
1
2868
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 caching section. So, in my code I add an item to the cache with an sqlCacheDependency, referencing the named sqlCacheDependency in the web.config and the database table it is to be based on (have enabled notificiations for that table). Fine. ...
7
1687
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 exposed the DA layer through a we service and store the connection string in the web.config file. Any recommendations? Thanks.
14
3506
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, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that web.config file is protected by IIS and Windows security which is the case. And another argument is that...
4
5381
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 connectionStrings defined in my web.config file, one for the development db and another for the production db. When I publish my app to the hosting site, I rename the two connection strings so that the production string will be the active string in the...
5
2133
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 the future by ASP.NET pages. I have created a constant that contains the connection string (as shown below).
3
1993
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 - <connectionStrings> <add name="TRM8.UI.My.MySettings.TRM8" connectionString="Data Source=SQLDATA;Initial Catalog=TRM8_PROD;Integrated Security=True"
9
2776
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 think it is easier and faster to store the connection strings in the config file. I was wondering if anyone has any opinion on this issue so that I can convince my manager. Thanks.
2
5395
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 ASP.NET applications that all manage connection strings in Web.config the same way, like this: This client has one Web.config file per application, and that one Web.config file is duplicated across all environments (i.e., dev machines, test,...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10153
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.