473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using ADO in managed C++ Class Library

I have an Unmanged ATL Dll, which I'm trying to gradually migrate to
managed C++, for easier use from C#-clients.

Internally the ATL-version uses ADO for accessing an Access-database.
This is done by #import'ing msado15.dll and using the smart pointers
(_ConnectionPtr, _RecordsetPtr etc.). As far as I know this should
work just fine in managed code.

The first time I try to call Open on the recordset it returns a
failure-HRESULT: 0x800A0BB9. I gather this means something like:
"Arguments are of the wrong type, are out of acceptable range, or are
in conflict with one another.".

This strikes me as odd, since this code runs just fine in the
ATL-version of the library. Any ideas anyone?

By the way, the connection to the database opens fine. It's only when
I try to open a recordset that I get an error.

Code:
_RecordsetPtr GetAdoRecordset(string sConStr, string sTableName)
{
_bstr_t bstrConStr;
bstrConStr = sConStr.c_str();
_bstr_t bstrTableName;
bstrTableName = sTableName.c_str();

_bstr_t bstrQuery;

bstrQuery = bstrTableName;

_ConnectionPtr pCon;
_RecordsetPtr pRs;

HRESULT hr;

try
{
hr = pCon.CreateInstance(__uuidof(Connection));
pCon->CursorLocation = adUseClient;
hr = pCon->Open(bstrConStr, L"Admin", L"", adOpenUnspecified);

hr = pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation = adUseClient;
pRs->PutRefActiveConnection(pCon.GetInterfacePtr());

// THIS FAILS! RETURNS 0x800A0BB9.
hr = pRs->Open(bstrQuery,vtMissing,adOpenStatic,adLockReadO nly,-1);

pRs->PutRefActiveConnection(NULL);
hr = pCon->Close();
return pRs.Detach();
}
catch(_com_error *e)
{
// errorhandler
}
catch(...)
{
// errorhandler
}
return NULL;
}
Nov 17 '05 #1
0 838

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Michael Howes | last post by:
I have some old C code that uses MFC and some C Run Time Library. I need to be able to call this from C# I thought i'd be able to create a Managed C++ DLL, tell the project it was using MFC, ...
12
by: Wayne | last post by:
We have some old win32 apps and I still need to support these applications. I'd like to do new and future enhancements in C#, if at all possible. Is there a way to use a .net assembly in a normal...
2
by: Jacob Cohen | last post by:
Under VC7.1, I am trying to wrap a native-C++ DLL that contains C++ objects in a Managed-C++ class library for use in a C# project. I created and compiled the native DLL under VC7.1 as a Win32...
3
by: mirek | last post by:
Hi, I've got problem building managed class library to wrap unmanaged code. I created managed class library using standard patten: #include "../Unmanaged/Class1.h" //Class1 unmanaged ...
3
by: Tommy Svensson \(InfoGrafix\) | last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C# application. Now, the only way, as I've understood it, is to go the Managed Extensions for C++ way. This means I have to...
1
by: Russell Mangel | last post by:
Sorry about the Cross-Post, I posted my question in the wrong group. Hello, What is the simplest way to create a dynamic collection (during run-time), using basic C (Struct data types). Since...
1
by: pikulsky | last post by:
There is a managed C++ class (ManagedClass) defined in one library (TestMCpp.dll), it has a method (funcTemplate) with template native type (NativeTemplate<int>). This library is built without any...
12
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
4
by: colin | last post by:
Hi, Is there an easy way to do 3d drawing using drect3d8 devices in c# ? please dont suggest using directx9 unless there is a way to use directx9 on devices with only direct3d8 support. the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.