Solved

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

Posted on 2002-07-21
1
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

623 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