|
-
Oct 19th, 2009, 11:37 PM
#1
Thread Starter
Junior Member
Complete Newbie - Global Variable
Ok I want to make a connection to a database. I can do that but it is obviously only in the scope of the function i have created.
Is there a way to leave that connection open perminantly so that other functions can call upon it.
Remember complete newbie here. Any help is greatly appreciated.
aaron
-
Oct 19th, 2009, 11:42 PM
#2
Re: Complete Newbie - Global Variable
You could do that but you shouldn't. ADO.NET was specifically designed NOT to work that way. You should create, open, close and destroy database connections on an "as needed" basis. You would store your connection string, or the components of your connection string, somewhere common so that it could be used by all connections.
-
Oct 20th, 2009, 12:00 AM
#3
Thread Starter
Junior Member
Re: Complete Newbie - Global Variable
The reason I wanted to do it this way is that I will be connecting to a remote database and will be having very frequent data checks, like at times every 5 seconds. I need to recreate the feel of live updates to a screen with new data that is being deliveried from other users on the system.
Would there be a better way of going about it?
-
Oct 20th, 2009, 12:08 AM
#4
Re: Complete Newbie - Global Variable
I think I may have misread your original post. because of the term "global" I was assuming that you wanted the one connection available throughout the app, which is what "global" usually means. In your case it's just a member variable you want. A local variable is declared within a specific method so its only available within that method. A member variable is declared within the type but outside all methods, so it's accessible from any method.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|