Skip to content

Sharing SQL connection throughout application

nickmollberg

Asked Oct 3, 2005, 7:36 AM EDT2 answers
Share
LinkedInX
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.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    Sharing connection is different than sharing tables.

    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.
    0
  • 0
    Where is the .config file? Where do I create the temp tables if i need to be able to access them across multiple forms? Do I create the tables in a separate .cs file with just code in it? How can I make sure the forms can see/use this data? I call multiple stored procs, but i have to use the same temp tables between all of them... so I need to be able to see them across multiple forms. Any ideas/examples/suggestions?
    0