473,666 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection String: Global.asax vs. web.config file

Upon reading through my ASP.NET book, I've learned how to place the
connection string in both locations in my application. Just due to habit, I
naturally want to place my SQL Server connection string in the asax
file...but are there really advantages to having in one file over the other?

Thanks
Nov 18 '05 #1
2 3085
Your web.config file is generally considered a better place because it's a
simple text file that is easily updated without needing to recompile
anything and changes go into effect immediately.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"D. Shane Fowlkes" <sh********** @h-o-t-m-a-i-l.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Upon reading through my ASP.NET book, I've learned how to place the
connection string in both locations in my application. Just due to habit, I naturally want to place my SQL Server connection string in the asax
file...but are there really advantages to having in one file over the other?
Thanks

Nov 18 '05 #2
I agree.

I use the web.config file because in our environment I
have to move an application from development to staging
(for testing) and then up to production. So rather than
making the change in the asax file and recompiling every
time before pushing the application up to the next stage I
just open the web.config and make the change.

I guess it's all just preference, whatever you feel most
comfortable in doing, but I vote for web.config

Jeremy
-----Original Message-----
Your web.config file is generally considered a better place because it's asimple text file that is easily updated without needing to recompileanything and changes go into effect immediately.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able- consulting.com
"D. Shane Fowlkes" <sh********** @h-o-t-m-a-i-l.com> wrote in messagenews:%2******* *********@TK2MS FTNGP12.phx.gbl ...
Upon reading through my ASP.NET book, I've learned how to place the connection string in both locations in my application. Just due to habit,
I
naturally want to place my SQL Server connection string
in the asax file...but are there really advantages to having in one

file over theother?

Thanks

.

Nov 18 '05 #3

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

Similar topics

4
2420
by: Leo Muller | last post by:
I am about to deploy my first ASP.NET project. But, I was used to store my variables, such as connection strings, in the global.asa file, in an application. However, these variables are different on my development and production server. If I use the global.asax file, then it is in the code behing, compiled part. Thus I can't change the setting on my production server. So where is the right place to save my connecting string? Leo
3
6119
by: hansiman | last post by:
I use Application_Start in global.asax to set some physical folder paths ie.: Application("pdf") = "c:\www\<site>\pdf\" global.asax uses code behind. When I move the project from the dev to the production server the global.asax code behind is compiled into the project.dll (i guess). This renders the physical paths unusable (naturally). Coming from
9
2140
by: Chris | last post by:
where is the best place to put the connection string for use through-out my app? right now I use, in every page/sub/etc: SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;database=xxx") for sql server 2k connection This connection is for all users,and is the only connection for this app. maybe in the Global.asax or webconfig file???
8
4859
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical differences in the way both the objects are handled by IIS. Are both objects stored in different memory spaces? I can access both the objects in my web page. I will be grateful if some one can help me understand the difference.
3
1971
by: Peter Afonin | last post by:
Hello, I put the connection string to the Web.config file, then in Global.asax I'm assigning this string to the application variable: cn = New OracleConnection cn.ConnectionString = AppCrypto.decrypt(ConfigurationSettings.AppSettings("ConnectionString")) Then I use this to variable to connect to the server:
9
4982
by: nbs.tag | last post by:
hey guys heres my question. I was told by a little birdie that .net 2.0 has the ability to read a connection string directly from a registry key. so in the registry key a string value of say : database=northwind;user=username;password=pw; is stored at software/myApp/connSTR in the registry, i was told its possible to just place <connectionStrings> <add name="asd"
37
8945
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use). I then change dynamically the connection string by doing : My.Settings.Item("ConnectionString") = "some connection sring" The problem is that if another user loggs in and chooses another client, then obviously it changes the connection string...
5
1776
by: djc | last post by:
is it still customary to use web.config and global.asax to store connection strings? For example storing the string in web.config and using application start procedure in global.asax to declare a global app variable? I'm an off and on hobby programmer and this was the last method recommended to me. As I start new projects I try to find out and follow the recommended practices of the day.
0
3762
by: Alias | last post by:
Hi - I have a site that runs on a development and production server. I'd like to programmatically change the connection string the provider uses in the web.config file and have the provider use the updated string. I am able to successfully change the string using this code in the Application_Start method of the Global.asax file: Dim csNew As ConnectionStringSettings
0
8445
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
8871
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
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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
6198
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
5664
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
4198
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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

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.