Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global database connection string in Windows Form Application

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
Is there a way to have one connection string, in this case an OleDbConnection to an Access database, that can be accessed globally from more than one class? Is it possible to have one connection string that covers an entire application? Thanks for any help.

Kyle
 
You can store it in the Registry and access it using the registry-access classes in the Win32 assembly.

If you're concerned about having various classes know what the connection string is, you could create a "Configuration" class that gets passed to the other objects via their constructors. Inside the Configuration class you could either hard-code the connectstring, or read it from the registry as above.

Chip H.
 
Thanks Chip,

I ended up storing the connection string as a public const string embeded in only one program and now it is available to all the other classes within the same namespace. That does the job well, I think.

Kyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top