Solved

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

Posted on 2002-07-21
1
224 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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