Solved

VC++ ODBC connection-how to open the database connection globally??

Posted on 2002-07-21
1
223 Views
Last Modified: 2013-11-20
I've used the VC++ wizard to connect to the database and generated some classes. Understand that each time I want to query a table, I have to call the Open(),OpenDataSource(), and OpenRowset() functions, which will open the database connection and fetch the rowset. When finished using the table, I will call Close() to close the table as well as the database connection. My question is, I don't want to close the database connection, I want the connection remain opened so next time when I query the table or other table (class) in the same database, I don't have to open the database connection again (which will take some time if I reopen the database connection).

I used to move the CSession m_session to a global variable, but it crashes when I exit the function!!
so how can I make the database connection to a global object. One thing maybe I should mention, I'm writing dll, not exe.
0
Comment
Question by:eugeneng
1 Comment
 

Accepted Solution

by:
cediger earned 100 total points
ID: 7169343
I have a class that is derived from CDatabase that I use for my database connection.  I call the CDatabase::OpenEx() function to establish the connection.  

I then create another class derived from CRecordset to hold the query data.  This is done using the Classwizard.  I open the recordset using an SQL statement, then process the record(s).  I then close the recordset, not the database.

I close the database once I am finished collecting all the information.

Hope this helps,
Cameron
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now