VS2010连接SQLserver 2008

http://blog.csdn.net/zhang2012liang/article/details/9414629



#pragma once


#include "targetver.h"

//注意要设置为动态使用MFC库
#include
#include
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
no_namespace \
rename("EOF","adoEOF")


//123456密码为自己设定的 如何将用户名sa的密码设置参看上一篇我转载的
#include "stdafx.h"
#include "iostream"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    CoInitialize(NULL);//数据库com初始化
    _ConnectionPtr m_pConnection;  //连接数据库对象指针
     HRESULT hr;  
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象 
_bstr_t strConnect = "Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=sa;Initial Catalog=RFID_DB;Data Source=.";
      m_pConnection->Open(strConnect,"","",adModeUnknown);
 cout<<"ddd";
system("PAUSE");


return 0;
}

你可能感兴趣的:(01,那些年的C++和MFC)