Problem in using database

Hi guys
I'm trying to access data base(SQL server) using c++, I understand that i must use ado to do this but every time i try to test a new code some error will pop up!! In the end I used this code and very strongly hoped that this will work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace

void main()
{
	_ConnectionPtr connection;
	_RecordsetPtr recordSet;
	CoInitialize(NULL);
	recordSet.CreateInstance(__uuidof(Recordset));
	connection.CreateInstance(__uuidof(connection));

	connection->Open("Provider=SQLOLEDB;Data Source=.\\SQLEXPRESS;Initial Catalog=myDatabase;Integrated Security=SSPI;","","",0);
	recordSet->Open("select * from Human",
					"Provider=SQLOLEDB;Data Source=.\\SQLEXPRESS;Initial Catalog=myDatabase;Integrated Security=SSPI;",
					adOpenStatic,
					adLockReadOnly,
					adCmdText);

	std::cout<<recordSet->GetRecordCount()<<std::endl;

	std::cin.get();
	recordSet->Close();
	connection->Close();
	CoUninitialize();
}


And I got this on 406th line of comip.h:
Unhandled exception at 0x75d69673 in mainDB.exe: Microsoft C++ exception: _com_error at memory location 0x002cfc4c..

Can you help me plz.
Topic archived. No new replies allowed.