Sharing SQL connection throughout application
Hey all,
I need to connect to my SQL server, and create some temporary tables.
I need to be able to access these tables throughout the application, so where should I connect to the SQL server, and create these temp tables so that they are available throughout the application?
I'm kind of a newbie here, so any examples would be awesome.
nickmollbergPosted Oct 3, 2005, 1:21 PM
Mahesh ChandPosted Oct 3, 2005, 12:55 PM
In general:
First of all, you need to define your connection string in your config file and access the value of connection string through a static class. For example, you can have a class member DatabaseUtility.ConnectionString, which will return connection string.
Now depending on how much data you are accessing. If you do not have too much data (10,000 records), then you may want to share the data among multiple forms. But if data is too much, you may only want to fetch as much data needed. To share the data, you can simply create a common object (class) and store that data in this object and load it first time. After that, only check if data is already loaded, there is no need to load that.
It also depends on, what table you are using where. If all of your forms are not using all tables, you may only want to get data from tables used on a specific form.