Solved

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

Posted on 2002-07-21
1
221 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

18 Experts available now in Live!

Get 1:1 Help Now