473,498 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ConnectionString

What is the best to pass a connection string around within an application.
For instance, if you have a static connection string that is determined at
login, how do you persist the connection string so that each call to the
database uses the same connection string without having to hard code it?
Nov 16 '05 #1
4 2220
=?Utf-8?B?Sm9obm55?= <Jo****@discussions.microsoft.com> wrote in
news:53**********************************@microsof t.com:
What is the best to pass a connection string around within an
application. For instance, if you have a static connection string that
is determined at login, how do you persist the connection string so that
each call to the database uses the same connection string without having
to hard code it?


I declare a static member in a class called Global and use that.

class Global {
public static string DBConnStr;

Then you can just do:

Global.DBConnStr = "xxxx";
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
Nov 16 '05 #2
Chad, I'm new to C# and OO so please forgive my ignorance but when the
connection string can change based on the user's requirements, how do you set
Global.DBConnStr? I mean, I can store the connection string in a flatfile or
XML file but I don't want to read from a file everytime I have to get the
connection string. What's the best way to handle this or am I just so
ignorant that I'm not following you? thanks, Johnny

"Chad Z. Hower aka Kudzu" wrote:
=?Utf-8?B?Sm9obm55?= <Jo****@discussions.microsoft.com> wrote in
news:53**********************************@microsof t.com:
What is the best to pass a connection string around within an
application. For instance, if you have a static connection string that
is determined at login, how do you persist the connection string so that
each call to the database uses the same connection string without having
to hard code it?


I declare a static member in a class called Global and use that.

class Global {
public static string DBConnStr;

Then you can just do:

Global.DBConnStr = "xxxx";
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/

Nov 16 '05 #3
Johnny <Jo****@discussions.microsoft.com> wrote:
Chad, I'm new to C# and OO so please forgive my ignorance but when the
connection string can change based on the user's requirements, how do you set
Global.DBConnStr? I mean, I can store the connection string in a flatfile or
XML file but I don't want to read from a file everytime I have to get the
connection string. What's the best way to handle this or am I just so
ignorant that I'm not following you? thanks, Johnny


You could put it in the application configuration file, then just use

ConfigurationSettings.AppSettings["ConnectionString"] etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Johnny,

I think that there is missing something from your scenario.

Why do they have to connect to another company. Is that because they have a
portable or whatever and are themselves on another location. Or is it that
there is/(are) a (more) central server(s) which has/(have) more databases.

In the last situation I think that I would make a simple general database
wherein I would keep the information you are talking about now, wherin is in
the login screen a little checkbox which tells to start the application to
change that information. The last is a quiet general methode so will be easy
understood by the user.

Just my thought

Cor
Nov 16 '05 #5

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

Similar topics

4
46669
by: Devante | last post by:
Hi, I am fairly new to ASP.NET and have been working on a web form that will allow a user to upload images to a database. I have found a sample web form that I have been trying to get working,...
4
1796
by: Shapper | last post by:
Hello, I have this connectionString in a DataReader: Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\db.mdb" It's working fine. Now i...
4
385
by: Devante | last post by:
Hi, I am fairly new to ASP.NET and have been working on a web form that will allow a user to upload images to a database. I have found a sample web form that I have been trying to get working,...
3
2313
by: Jim Andersen | last post by:
Hi, I would appreciate if someone could explain this behaviour, and maybe offer a better solution. I have been working with the GridView control. And SqlDataSource. It works great if I do:...
5
6498
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
7004
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...
0
7167
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,...
1
6890
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...
0
5464
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,...
1
4915
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...
0
4593
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...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
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 ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.