Hello guys,

I'm currently trying to rework an older project. It uses the Dao interface to connect to a MS-Access database. It now needs to connect to a SQL CE Database using the ADO driver.

However, I keep getting the IDispatch error, see below.

CJapRecordsets is a class with membervariables that inherits from _RecordsetPtr.

I'm not sure if it should inherit _RecordsetPtr or CADORecordset.

I did try to change it to CADORecordset(this seems to be working out better - there are functions that do not exist in _RecordsetPtr even though I need them). However I get an IDispatch Error #3105 here...

rs = new CJapRecordsets(Global::MyDatabase);

		if(!Global::MyDatabase->IsOpen())					
		{
					Global::MyDatabase->Open("Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\JAP-MAIN.sdf;");	
		}
		
		

		if(!rs->IsOpen())
		{
			// This causes the IDispatch error	
			rs->Open(Global::MyDatabase->GetActiveConnection().GetInterfacePtr(),"SELECT * FROM Gesamt", 1);
		}

I can open the database successfully and check if the recordset is open or closed. However, upon trying to execute a select query, I keep getting an IDispatch error.

#include "stdafx.h"
#include "JAP.h"
#include 
#include "JapRecordsets.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CJapRecordsets

IMPLEMENT_DYNAMIC(CJapRecordsets, CJapRecordsets)

CJapRecordsets::CJapRecordsets(CADODatabase* pdb)
	: CADORecordset(pdb)
{

	m_NAME1 = _T("");
	m_VORNAME1 = _T("");
	m_NAME2 = _T("");
	m_VORNAME2 = _T("");
	m_ARTIKEL = _T("");
	m_TITEL = _T("");
	m_UNTERTITEL = _T("");
	m_AUFLAGE = _T("");
	m_ORT = _T("");
	m_JAHR = _T("");
	m_BJAHR = _T("");
	m_FORMAT = _T("");
	m_ILLUSTRA = _T("");
	m_EINBAND = _T("");
	m_BEIGABEN = _T("");
	m_NACHWEIS = _T("");
	m_ZUSTAND = _T("");
	m_W_HRUNG = _T("");
	m_ZUSCHLAG = 0.0f;
	m_SIGEL = _T("");
	m_KENNZ = _T("");
	m_SORT = 0.0;
	m_JAP = 0;
	m_MYLISTFLAG = FALSE;
	m_ID = 0;
	m_nFields = 25;

	m_nDefaultType = 0;
}


CString CJapRecordsets::GetDefaultDBName()
{
	return _T(".\\JAP-MAIN.sdf");
}

CString CJapRecordsets::GetDefaultSQL()
{
	return _T("SELECT * FROM [Gesamt]");
}

void CJapRecordsets::DoDataExchange(CDataExchange* pDX) 
{
		
// Currently empty, must be changed later, dno how though
// Member variables must be asigned
// m_NAME1 must be the cell value of the column "NAME1"
}

/////////////////////////////////////////////////////////////////////////////
// Diagnose CJapRecordsets

#ifdef _DEBUG
void CJapRecordsets::AssertValid() const
{
//	CADORecordset::AssertValid();
}

void CJapRecordsets::Dump(CDumpContext& dc) const
{
//	CADORecordset::Dump(dc);
}
#endif //_DEBUG

Recommended Answers

All 2 Replies

I've never seen a .sdf file opened with MFC. ( but ... )

Is it possible to set an ODBC entry to that file and hit it through ODBC?
If so, can you see it when you use MS Query?

I've never seen a .sdf file opened with MFC. ( but ... )

Is it possible to set an ODBC entry to that file and hit it through ODBC?
If so, can you see it when you use MS Query?

You can open a .sdf file in MFC using ADO(I'm sure).

Using ODBC is NOT an option.

The program will be,together with the database, on a CD. Meaning you can directly browse the database using the program - there is no option of setting up an ODBC database(not possible for this project).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.