473,802 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection string and web.config

Hello,

I'm developing a website which has a SQL database working through ADO.NET.

When I'm development site I have my personal IIS server as well as my
personal SQL server.
All my connections strings are pointing to this local SQL server.
When I need to upload the modifications to running website I have to
manually change all SQL connections strings because the running SQL server
is placed on other machine and has a different name.

To minimize this extra job I put my connection string into a key inside
web.config file but, even doing this, on all upload job I need to configure
this file.

Another similar problem is related to design time which uses also a
connection to my local SQL server for some DataSet and DataAdapter objects.
When another developer tries to edit these objects it receives an error
message due the same reason, his local SQL server has another name.

How can I make this easier than that?
Is there any way to solve this?

Kindest regards,
Fernando.
Nov 18 '05 #1
3 2061
Hi Fernando,

To get around the issue of different environments, you can use a whole set
of keys, with a different key in the web.config for every deployment
scenario, including running on the localhost. No edits are required
to the web.config once it is set.

For example, these two keys are for the datasource:

<add key="localhost_ DataSource" value="xxxxx" />
<add key="intranet_c orp_com_DataSou rce" value="yyyy" />

In my .vb code, I read the server name and convert it into the key that I
need automatically:

strSERVER_NAME = Replace(Request .ServerVariable s("SERVER_NAME" ), ".", "_")
strDataBaseServ er = ConfigurationSe ttings.AppSetti ngs(strSERVER_N AME &
"_DataSourc e")
Does this help?

Ken
MVP [ASP.NET]

"Fernando Poinho Malard" <fe******@graph system.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello,

I'm developing a website which has a SQL database working through ADO.NET.

When I'm development site I have my personal IIS server as well as my
personal SQL server.
All my connections strings are pointing to this local SQL server.
When I need to upload the modifications to running website I have to
manually change all SQL connections strings because the running SQL server
is placed on other machine and has a different name.

To minimize this extra job I put my connection string into a key inside
web.config file but, even doing this, on all upload job I need to
configure
this file.

Another similar problem is related to design time which uses also a
connection to my local SQL server for some DataSet and DataAdapter
objects.
When another developer tries to edit these objects it receives an error
message due the same reason, his local SQL server has another name.

How can I make this easier than that?
Is there any way to solve this?

Kindest regards,
Fernando.


Nov 18 '05 #2
For local SQL server you should use (local) as a server name (in round
brackets) not your machine name.
So other developer will use his own local SQL server.

It does not seems to be a big job to edit web.config once you are moving it
to production.

But even if you are moving it everyday (like fixing bugs, ... ) then just do
not copy web.config over the one that exists.

George.
"Fernando Poinho Malard" <fe******@graph system.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello,

I'm developing a website which has a SQL database working through ADO.NET.

When I'm development site I have my personal IIS server as well as my
personal SQL server.
All my connections strings are pointing to this local SQL server.
When I need to upload the modifications to running website I have to
manually change all SQL connections strings because the running SQL server
is placed on other machine and has a different name.

To minimize this extra job I put my connection string into a key inside
web.config file but, even doing this, on all upload job I need to configure this file.

Another similar problem is related to design time which uses also a
connection to my local SQL server for some DataSet and DataAdapter objects. When another developer tries to edit these objects it receives an error
message due the same reason, his local SQL server has another name.

How can I make this easier than that?
Is there any way to solve this?

Kindest regards,
Fernando.

Nov 18 '05 #3
Hi Ken,

This seems to solve the runtime problem but not the design time problem once
the connection string is placed inside the code and, at design time, I can't
change this value...

Another issue is if user has more than one SQL instance running...does
"SERVER_NAM E" represents the first instance when machine has more than one
installed?

Regards,
Fernando.

"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Fernando,

To get around the issue of different environments, you can use a whole set
of keys, with a different key in the web.config for every deployment
scenario, including running on the localhost. No edits are required
to the web.config once it is set.

For example, these two keys are for the datasource:

<add key="localhost_ DataSource" value="xxxxx" />
<add key="intranet_c orp_com_DataSou rce" value="yyyy" />

In my .vb code, I read the server name and convert it into the key that I
need automatically:

strSERVER_NAME = Replace(Request .ServerVariable s("SERVER_NAME" ), ".", "_")
strDataBaseServ er = ConfigurationSe ttings.AppSetti ngs(strSERVER_N AME &
"_DataSourc e")
Does this help?

Ken
MVP [ASP.NET]

"Fernando Poinho Malard" <fe******@graph system.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hello,

I'm developing a website which has a SQL database working through ADO.NET.
When I'm development site I have my personal IIS server as well as my
personal SQL server.
All my connections strings are pointing to this local SQL server.
When I need to upload the modifications to running website I have to
manually change all SQL connections strings because the running SQL server is placed on other machine and has a different name.

To minimize this extra job I put my connection string into a key inside
web.config file but, even doing this, on all upload job I need to
configure
this file.

Another similar problem is related to design time which uses also a
connection to my local SQL server for some DataSet and DataAdapter
objects.
When another developer tries to edit these objects it receives an error
message due the same reason, his local SQL server has another name.

How can I make this easier than that?
Is there any way to solve this?

Kindest regards,
Fernando.

Nov 18 '05 #4

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

Similar topics

3
2155
by: Varun | last post by:
I have a solution which contains windows,web,mobile presentations. Now i want to share the connection string in the web.config file. i want to write a method in a common layer where i can retrieve the connection string for all the presentations layers How can i do that? Any suggestions or urls are suggested? Thank you
6
2163
by: H | last post by:
This is a question that has haunted me for quite some time. if you build a 4 tier database application where the 4th tier is the database server (MS SQL 2000), where do you build the connection string? The obvious answer is to hard code it into the middle layer and use a config file. The problem is the database application needs to be distributed to purchasing clients. Therefore, you do not know, at development, what the SQL
6
1785
by: Jon Davis | last post by:
I like the drag-and-drop accessibility of dragging a table to a Web Forms designer and seeing a SqlDataAdapter automatically created for me.. being able to create a DataSet from that is fun and exciting, because now with this schema based data outline Visual Studio provides me with a typed class for managing data complete with Intellisense menus exposing my own field names as C# object properties ... cool .. Anyway, I have a problem. I...
6
1511
by: Mike L. | last post by:
Hi, Pls, beware that I'm new to this :) I've developed several web appl, either with ASP or ASP.NET. All using SQL server as the back end. In my development environment, I have a single server running Win2K, which serves as Web Server and SQL server as well. And, since my hosting (production server) using the same config; ie: using a single server to serve both web server and SQL server; it's always been easy
19
2535
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet GetCategories() { SqlConnection conn = new SqlConnection("Data Source=DEVSERVER;Initial Catalog=XXXX;User ID=X;Password=Y");
14
3509
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...
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
6613
by: Thorsten Dittmar | last post by:
Hi, I don't get it. I'm using a typed dataset with table adapters and all that stuff. I have the database server running locally on my development system. Now: when creating a tableadapter I'm asked for the connection and the connection string is automatically stored in the settings. So far so good. However, my typed dataset is declared within a dll that implements other
8
6340
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource. Just to get it to work, I hard-coded the username and password of a SQL Server account in the connectionstring in web.config. Once I confirmed that this worked on the web server, I wanted to remove the hard-coded password from web.config, so I...
2
5398
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
9699
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
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10285
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
9114
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
7598
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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.