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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharing a SQL connection throughout app 1

Status
Not open for further replies.

vixen925

IS-IT--Management
Oct 3, 2005
7
US
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 have several stored procedures, all of which need to be able to use the same temp tables - so i can't create a new sqlconnection for each stored proc, so how do I create the connection/temp tables so they're available to all forms within my application?


I'm kind of a newbie here, so any examples would be awesome.
 
I need to keep the connection open... if i close it, the temp tables will be destroyed, and I need them throughout the application, across multiple calls to stored procedures, and while moving between different forms.

In your main code sample, where do you put this code? Does it need to be in a standalone .cs file? How can i make it accessible from my other forms?

Would I create my temp tables in this standalone .cs file as well?
 
I just put this in a seperate .cs file so I could easily port it to other applications. The connection should stay open unless you explicitly close it. Closing a DataReader will not close your connection (in this case, only the DBLibrary.Disconnect() method will do that). If you stick it in the same namespace as your project, you can create a new DBLibrary object in my main form/class, call the connect method, and then pass the class to whoever needs to connect to the database. I have only had experience working with Access databases, so I can't help you much working with stored procedures.

--Brad

"Life is too important to be taken seriously" --Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top