Link to home
Start Free TrialLog in
Avatar of rgcomm
rgcomm

asked on

Need help with closing database.

Accessing ODBC-dbase in Visual C++, having trouble closing database.
I have tried the following:

1. CDatabase db;
   db.Close(); // Has no effect on database.

2. CTestSet ts;
   ts.Close(); // error message when executed:
                              "Debug Assertion Failed!"

3. CRecordset rs;
   rs.Close(); // error message when executed:
                               "Debug Assertion Failed!"

Please Help.
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

R U closing without opening the database?...

Just try

if(rs.IsOpen())
rs.Close();


VinExpert
Hi
1. CDatabase db;
   db.Close();
Since default declaration no assertion hence no error no effect.

2. CTestSet ts;
   ts.Close();
Assertion because U have not opened it

3. CRecordset rs;
   rs.Close();
Assertion because U vave not opened it

If U want to close a databse U have to close all the recordsets associated and then close the database.
Avatar of rgcomm

ASKER

The file is still open, see code:

testSet.cpp

CString CTestSet::GetDefaultConnect()
{  
   return _T("ODBS;DSN=TestDB");
}

CString CTestSet::GetDefaultSQL()
{
    return _T("[TESTFILE]");
}

testView.cpp

Cdatabase db;
CRecordset rs;
CTestSet ts;

// TESTFILE is Open at this point

void CTestView::OnButton1()
{
    if(rs.IsOpen())
       rs.Close();
    if(ts.IsOpen())
       ts.Close();
    if(db.IsOpen())
       db.Close();
}    

// TESTFILE is still Open after Button 1

Thank you for your help
What do U mean Open?
I don't see any rs.Open() here? how come it is open if U R not openeing it?
ASKER CERTIFIED SOLUTION
Avatar of Vinayak Kumbar
Vinayak Kumbar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgcomm

ASKER

When I executed the program it locked up the database just from the GetdefaultConnect & GetdefaultSQL without using the open function.

It's a dbase (.dbf) problem. As soon as I switched the data over to Access (.mdb) the problem was solved.
Avatar of rgcomm

ASKER

I did not have a open function, dbase (.dbf) opened the file at execution and would not allow me to close.

I imported the data into Access (.mdb) and now everything is working fine.

Thank you again for all your help.