最近接个项目是用C++做的,本人以前是做java的,未曾使用过SQL SERVER,没办法,项目还要进行... ... 
下面是我写的代码,编译没出错,但就是运行的时候报了个异常:'System.Runtime.InteropServices.SEHException'谁来帮下忙,不胜感激。。
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")
#include<iostream>
#include<iomanip>
#define _WIN32_DCOM
#include <windows.h>
#include <malloc.h>
#include <objbase.h>    using namespace std;   int main(){
   ::CoInitialize(NULL);
   _ConnectionPtr m_pConnection=NULL;
   _RecordsetPtr m_pRecordset=NULL;
   _variant_t vid,vname,vage; 
   try{
m_pConnection.CreateInstance(_uuidof(Connection));
m_pRecordset.CreateInstance(_uuidof(Recordset));
m_pConnection->ConnectionString="driver={SQL Server};Server=local;DATABASE=csv;UID=sa;PWD=zhangzq123";

m_pConnection->Open("","","",adModeUnknown);
cout<<"haha"<<endl;
_bstr_t strSql="select * from dbo.t_test";

m_pRecordset->Open(_variant_t(strSql),(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
while(!m_pRecordset->GetEndOfFile()){
vid=m_pRecordset->GetCollect("id");
       vname=m_pRecordset->GetCollect("name");
      vage = m_pRecordset->GetCollect("age");
if(vid.vt!=VT_NULL&&vname.vt!=VT_NULL&&vage.vt!=VT_NULL)
{
cout.setf(ios::left);
cout<<setw(14)<<(char*)(_bstr_t)vid<<endl;
cout<<setw(14)<<(char*)(_bstr_t)vname<<endl;
cout<<setw(8)<<vage.lVal<<endl;
cout<<endl;
}
m_pRecordset->MoveNext(); 
    }
   }catch (_com_error e)
   {
cout<<"hahahahahahahhaahahaha"<<endl;
   }
m_pRecordset->Close();
m_pConnection->Close();
m_pRecordset = NULL;
m_pConnection = NULL;
 }