Hi,
Im trying to connect to my sql database and generally play around but I get the following error: error C3867: '_com_error::Description': function call missing argument list; use '&_com_error::Description' to create a pointer to member I think it has something to do the import of the msado15.dll.
Obviously if I take out the error handling it runs but it returns random characters.

Anyone got any ideas?

#include <windows.h>
#include <stdio.h>

#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
		no_namespace rename("EOF", "EndOfFile")




int main(int argc, char* argv[])
{
	HRESULT hr = S_OK;
	try
	{
		CoInitialize(NULL);
		//Define string variables
		_bstr_t strCnn("Provider=SQLOLEDB.1;Persist Security Info=False;"\
				 "User ID=Manager;Initial Catalog=DevTest;Data "\
				 "Source=WS-VISTA\\RICHY");
						_RecordsetPtr pRstAuthors = NULL;
		
		//Call Create instance to instantiate the Record Set
		hr = pRstAuthors.CreateInstance(__uuidof(Recordset));

		
		if(FAILED(hr))
		{
			printf("Failed creating record set instance\n");
			return 0;
		}

		pRstAuthors->Open("SELECT Name,Number FROM TestTable",strCnn, adOpenStatic,
							adLockReadOnly, adCmdText);

		//Declare a variable of type _bstr_t
		_bstr_t valField1;
		int valField2;

		pRstAuthors->MoveFirst();

		//Loop through the record set
		if(!pRstAuthors->EndOfFile)
		{
			while(!pRstAuthors->EndOfFile)
			{
				valField1 = pRstAuthors->Fields->GetItem("Name")->Value;
				valField2 = pRstAuthors->Fields->GetItem("Number")->Value.intVal;
				printf("%d - %s\n",valField2,(LPCSTR)valField1);
				pRstAuthors->MoveNext();
			}
		}
	}
	catch(_com_error & ce)
	{
		printf("Error:%s\n,",ce.Description);
	}

	CoUninitialize();
	return EXIT_SUCCESS; 
}

Edit: nevermind fixed it.

Changed line 55 to:

printf("Error:%s\n,",(char*)ce.Description());

I tried to compile it with vc++ 2008 express and got other errors. Must be some header files missing -- I have no idea how to correct them.

1>c:\dvlp\test2\test2\debug\msado15.tlh(2375) : error C2059: syntax error : '<L_TYPE_raw>'
1>c:\dvlp\test2\test2\debug\msado15.tlh(2375) : error C2238: unexpected token(s) preceding ';'
1>c:\dvlp\test2\test2\test2.cpp(27) : error C2065: '_RecordsetPtr' : undeclared identifier
1>c:\dvlp\test2\test2\test2.cpp(27) : error C2146: syntax error : missing ';' before identifier 'pRstAuthors'
1>c:\dvlp\test2\test2\test2.cpp(27) : error C2065: 'pRstAuthors' : undeclared identifier
1>c:\dvlp\test2\test2\test2.cpp(30) : error C2065: 'pRstAuthors' : undeclared identifier
1>c:\dvlp\test2\test2\test2.cpp(30) : error C2228: left of '.CreateInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\dvlp\test2\test2\test2.cpp(30) : error C2065: 'Recordset' : undeclared identifier

<snip>

Thanks for looking btw.

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.