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

Home Posts Topics Members FAQ

ConnectionStrin g - 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.Con nectionstring" value="workstat ion
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 connectionstrin g in the windows installer?
Thanks,
Dean
Nov 18 '05 #1
2 2003
One possible solution. Use Environment.Mac hineName 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.co m> wrote in message
news:ed******** ******@TK2MSFTN GP09.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.Con nectionstring" value="workstat ion
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 connectionstrin g 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 <CustomSectio n> 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="Connection String" Value="my connection string" />
</appSettings>

To access the appSettings Value, you need to use
ConfiugrationSt tings.AppSettin g["ConnectionStri ng"]. This uses the
NameValueFileSe ctionHandler, which returns a
System.Collecti on.Specialized. NameValueCollec tion 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/cpgrfaccessinga ppsettingssecti on.asp

- Using <CustomSectio n> 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 <myNameValueSec tion>
<myNameValueSec tion>
<add key="Connection String" Value="my connection string" />
<myNameValueSec tion>

to read the data, you will need the following code snippet
NameValuecollec tion config =
ConfigurationSe ttings.GetConfi g("myNameValueS ection");
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.co m> wrote in message
news:ed******** ******@TK2MSFTN GP09.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.Con nectionstring" value="workstat ion
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 connectionstrin g 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
1973
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 securing the server. Included in this was revoking public access to the system table objects. Can someone post the URL where I can pick this up, or drop me a note on contacting them for a copy of the document?
136
9457
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
13
2284
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 = 2, Option4 = 3
1
1415
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
1830
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) Group relevant .aspx files into subfolders within your project etc.
5
1739
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" value="server=localhost;uid=sa;password=MyPwd;database=MyDB"/> </appSettings>
10
3482
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 somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
3
2246
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 Enterprise Libraries data layer (if possible) - Use of providers (if possible) - use of factories (if possible) - use of caching - Session management
5
6526
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" EnableCaching="True" ConnectionString="<%$ ConnectionStrings:OrderingProcess %>" CacheDuration="60" FilterExpression="ID = {0}" RunAt="server">
0
9480
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,...
0
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
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
7496
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
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.