473,383 Members | 1,733 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,383 software developers and data experts.

ConnectionString - best practices ques

We currently distribute a web application to serveral servers for a
customer. We have been putting the connection string in our web.config file
under <appSettings> <add key="dbconn.Connectionstring" value="workstation
id=server025....... etc.

When we deploy the application we have to change the workstation id and
source parameters to name the server where the database will be.

We tried to simply specify localhost however VS.NET could not deal with this
because the data connection in server explorer has to have the read dev box
server name.

Questions are:
Is this the best place to put the connection string?
Is there any way to specify "localhost" and still get VS.NET to work with
that?
Is there any way I can tweak this connectionstring in the windows installer?
Thanks,
Dean
Nov 18 '05 #1
2 1986
One possible solution. Use Environment.MachineName to get the name of the
local machine. Use that in your Connection String.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"G. Dean Blake" <De**@nospam.com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
We currently distribute a web application to serveral servers for a
customer. We have been putting the connection string in our web.config file under <appSettings> <add key="dbconn.Connectionstring" value="workstation
id=server025....... etc.

When we deploy the application we have to change the workstation id and
source parameters to name the server where the database will be.

We tried to simply specify localhost however VS.NET could not deal with this because the data connection in server explorer has to have the read dev box server name.

Questions are:
Is this the best place to put the connection string?
Is there any way to specify "localhost" and still get VS.NET to work with
that?
Is there any way I can tweak this connectionstring in the windows installer? Thanks,
Dean

Nov 18 '05 #2
Here are few options for storing connection string,

you can store the connecting string information in your web.config file in
two ways:
- Using <appSettings> Section
- Using <CustomSection> Section.

- Using <appSettings> Section:
The predefined <appSettings> section can be placed in any web.config file
or the machine.config file. This section is useful for storing
name-value pairs of data. An example of the use of the <appSettings>
section is as follows:
<appSettings>
<add key="ConnectionString" Value="my connection string" />
</appSettings>

To access the appSettings Value, you need to use
ConfiugrationSttings.AppSetting["ConnectionString"]. This uses the
NameValueFileSectionHandler, which returns a
System.Collection.Specialized.NameValueCollection object. The collection
implements the IEnumerable interface so you can enumerate the collection,
or read values directly for any valid key,

Accessing the appSettings Section
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpgrfaccessingappsettingssection.asp

- Using <CustomSection> Section:
You can create your own custom sections in a configuration file. The
easiest way to do this is to configure one of the
pre-existing configuration section handlers, assuming your section uses one
of the generic structures such as name-value
data, or single tag data.
In this particular case you might use the Name-Value data. To do this, you
need to use the pre-defined section handlers.

For example, you can define a section called <myNameValueSection>
<myNameValueSection>
<add key="ConnectionString" Value="my connection string" />
<myNameValueSection>

to read the data, you will need the following code snippet
NameValuecollection config =
ConfigurationSettings.GetConfig("myNameValueSectio n");
Foreach (string key in config.keys)
{
label1.Text = "Key:" + key.toString();
label2.Text = "Value:" + config[key];
}

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"G. Dean Blake" <De**@nospam.com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
We currently distribute a web application to serveral servers for a
customer. We have been putting the connection string in our web.config file under <appSettings> <add key="dbconn.Connectionstring" value="workstation
id=server025....... etc.

When we deploy the application we have to change the workstation id and
source parameters to name the server where the database will be.

We tried to simply specify localhost however VS.NET could not deal with this because the data connection in server explorer has to have the read dev box server name.

Questions are:
Is this the best place to put the connection string?
Is there any way to specify "localhost" and still get VS.NET to work with
that?
Is there any way I can tweak this connectionstring in the windows installer? Thanks,
Dean

Nov 18 '05 #3

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

Similar topics

2
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and detailed a nyumber of best practices about...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
13
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 =...
1
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's with type of control btnSubmit, txtName, etc. 2)...
5
by: Kent Johnson | last post by:
Hi all, I have accidentally deleted my web.config file so I'll have to recreate it. I have tried this in my Web.config file: <configuration> <appSettings> <add key="ConnectionString"...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
3
by: John Dalberg | last post by:
I am looking for an ASP.NET application on CodePlex which exemplifies best practices for the following: - Use of interfaces - Seperation of the UI, business and data tiers - Data Tier that uses...
5
by: Radu | last post by:
Hi. In a repeater I have as ItemTemplate the following, among others, and everything works great: <asp:SqlDataSource ID="LocationSqlDataSource" SelectCommand="SELECT blah-blah-blah"...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.