34,593
社区成员
发帖
与我相关
我的任务
分享
//stdafx.h
#import "C:\Program Files\Common Files\System\ADO\msado15.dll"\
no_namespace rename("EOF","sqlEOF")
#include <icrsint.h>
//应用程序InitInstance方法中加入
::CoInitialize(NULL);
//声明
public:
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_CommandPtr m_pCommand;
//调用
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pCommand.CreateInstance(__uuidof(Command));
m_pConnection->ConnectionString="Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=test;User ID=sa;Password=123456";
m_pConnection->ConnectionTimeout=60;
HRESULT hr=m_pConnection->Open("","","",0);
if(hr!=S_OK)
MessageBox(_T("Can not connection to database"));
MessageBox(_T("success!"));
m_pConnection->Close();