#include "stdafx.h" #include <iostream> #include <iomanip> #include "windows.h" using namespace std; #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","EndOfFile") int _tmain(int argc, _TCHAR* argv[]) { ::CoInitialize(NULL); _RecordsetPtr recordP("ADODB.RecordSet"); _ConnectionPtr connp("ADODB.Connection"); try{ connp.CreateInstance("ADODB.Connection"); _bstr_t strSQL="Provider=SQLOLEDB;Server=WIN-4MOED8K4727,1433;DataBase=proTest;UID=cjr;PWD=123"; connp->Open(strSQL,"","",adModeUnknown); cout<<"connection success"<<endl; if(connp==NULL){ cout<<"error"<<endl; } }catch(_com_error e){ cout<<e.Description()<<endl; } return 0; }
时间: 2024-10-24 16:54:42