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
Hi guys,

I know this is ASP.NET but I thought you may still know the answer even though I'm applying it to a windows form.
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
 
Hey Kyle,

Yup, there's a few ways to do it.

At my old gig, we were doing a VB desktop app, and had one of our code pages set as the start page in the dll and put the Main() sub in there. In it, we declared all the properties of our connection string and set it to a global variable.

In one of my recent asp.net dll's, I did the same thing...but I can't find the code
:p

However, a buddy suggested this idea:
Create a module, and in it declare:
Public Const dbConnect = "connection string"

That will allow for all your code to access it from anywhere (heh, well in theory).

Give it a try, and if it doesn't fly let me know. I'm sure I have that code around here somewhere....

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top