ConnectionString

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
=?Utf-8?B?Sm9obm55?= said:
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/
 
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
 
Johnny said:
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.
 
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
 
Back
Top