mfc >> CDatabase

by David Mohandas » Thu, 03 Jun 2004 23:24:44 GMT

I am getting an error "Dialog Failed" when i use the CDatabase Open(NULL)
method. It should bring up the ODBC DSN dialog where we select the DSN. It
is working once where it lets us pick the DSN, i get this error only the
second time i call the Open method. This issue is happening only on XP
machines and also only if my application is built with VC7.0.

Has anybody run into similar issue.




mfc >> CDatabase

by KS » Thu, 03 Jun 2004 23:35:02 GMT


See if this helps ... first hit from GOOGLE

http://www.kbalertz.com/Feedback_125794.aspx

KS








mfc >> CDatabase

by David Mohandas » Fri, 04 Jun 2004 00:38:06 GMT

I checked and this says that the issue had been fixed in 2.2, i am on Visual
Studio 7.0. Also it states that this issue happens on a USRDLL mine is a
executable. I don't think it is the same issue.





Open(NULL)
It




CDatabase

by QWx1cg » Wed, 15 Mar 2006 17:36:28 GMT

In the header file:
#ifndef NAME_H
#define NAME_H
extern CDatabase db;
extern CRecordset rs;
#endif

In the source file:
db.OpenEx("DRIVER=SQL
SERVER;SERVER=SERVNAME;UID=SA;PWD=;DATABASE=DBNAME",CDatabase::forceOdbcDialog);

Error:
Compiling...
MAINNAME.cpp
NAME.CPP
C...CPP(7) : error C2143: syntax error : missing ';' before '.'
C... : error C2501: 'db' : missing storage-class or type specifiers
C...CPP(7) : error C2371: 'db' : redefinition; different basic types
c...NAME.h(4) : see declaration of 'db'
C...NAME.CPP(7) : error C2143: syntax error : missing ';' before '.'
Why?

What must I do ?
Would you suggest?



CDatabase

by David Wilkinson » Wed, 15 Mar 2006 17:54:20 GMT





Alur;

It sounds as if the compiler doesn't know about the CDatabase class. How
are you including MFC in this project? You have to include the MFC
headers somewhere. Normally in an MFC project they are included in your
stdafx.h, and you must include this file at the top of every .cpp file.

David Wilkinson


CDatabase

by QWx1cg » Wed, 15 Mar 2006 18:34:25 GMT

I'd included the MFC
stdafx.h at the top of name .cpp file.


CDatabase

by David Wilkinson » Wed, 15 Mar 2006 19:03:45 GMT





Alur:

And what is in your stdafx.h? Is this a wizard-generated MFC project?
You should see something like

#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC OLE automation classes
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

To get database ODBC support you also need

#include <afxdb.h>

(Maybe this is what is missing.)

David Wilkinson


CDatabase

by QWx1cg » Fri, 17 Mar 2006 17:56:28 GMT

Thank you.
This is a wizard-generated MFC project.
Everything was mentioned by you is in stdafx.h



Similar Threads

1. CDatabase error

Dear All,

I am trying to use CDatabase class and include the class <afxdb.h>, but the
following error occurs,

Linking...
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator
new(unsigned int)" (??2@YAPAXI@Z) already defined in libcpd.lib(newop.obj)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved external symbol
__endthreadex referenced in function "void __stdcall AfxEndThread(unsigned
int,int)" (?AfxEndThread@@YGXIH@Z)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved external symbol
__beginthreadex referenced in function "public: int __thiscall
CWinThread::CreateThread(unsigned long,unsigned int,struct
_SECURITY_ATTRIBUTES *)"
(?CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRIBUTES@@@Z)
Debug/20050722.SecondTrial.exe : fatal error LNK1120: 2 unresolved externals

I dunno what is going on, is there anyone can help me a hand?

Thanks,


2. CDatabase Transactions

3. Catching CDatabase Exceptions?

Hi all,

'Nother question.  I have a piece of code that is using the MFC CDatabase 
object to connect to a database.  It executes a SQL statement against SQL 
Server using the ExecuteSQL() function.  This brought up the question of 
capturing the exceptions that are thrown by the CDatabase object.  Is there 
a way for me to trap it in my code and use my own error-handling mechanism? 
I tried putting it in a try...catch block with no success.  As always, any 
ideas are appreciated!

By the way, the *only* things I'm using MFC for are the CDatabase and 
CRecordset objects.  Does anyone out there know of any well-tested, 
"light-weight" wrappers for ODBC?  (I'm stuck with ODBC for this project, 
BTW).  The only functions I'm using in the CDatabase and CRecordset are 
ExecuteSQL() and retrieving a "scalar" value (i.e., I'm reading a single 
row, single column table) via the CRecordset.  I'd like to get away from MFC 
completely, but also don't want to have to write my own ODBC wrappers if I 
can avoid it.

Thanks! 


4. [newbie]: CDatabase problem

5. Access CRecordset and CDatabase database

Hi,I want to use class CRecordset to add some record to several tables
in access 2003???I have registered an ODBC database,and create a
CRcordset by ClassWizard.Now I can't add records to the table which I
have opened?? I am confused about this peoblem.
thank you.

6. Access CRecordset and CDatabase database

7. Accessing Stored Procedure using CDatabase and CRecordset

Hi all,

Is it possible to do a oBulkFieldExchangefor getting a bulk of records 
from a stored procedure, which takes a value as input and use that value in 
the herepart to filter a electquery.

Or how can I use CDatabase and CRecordet to access different Stored 
Procedures, which do different actions, like just return a record set , 
return many UTPUTvalue or just ETURNa string, etc. ?

Is there any documentation related to this available ?

Thanks in advance...
Umesh

8. ADO vs CDatabase