m_pConnection->Open(strConnect,"","",adModeUnknown);出错!
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include
#include //for setw()
using namespace std;
int main()
{
::CoInitialize(NULL);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
try
{
m_pConnection.CreateInstance("ADODB.Connection");
// 设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect= "Provider=SQLOLEDB;Server=(local);Database=grid;uid=sa;pwd=ksh;";
//_bstr_t strConnect = "Provider=SQLNCLI10;Password=ksh;Persist Security Info=True;User ID=sa;Initial Catalog=grid;Data Source=(local);";
//m_pConnection->Open("driver={SQL Server};Server=127.0.0.1;DATABASE=grid;UID=sa;PWD=ksh","","",adModeUnknown);
//m_pConnection->Open("driver={SQL Server};User ID=sa;Password=ksh;Server=(local);DATABASE=grid","","",adModeUnknown);
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
cerr <
}
注释掉的哪几种连接都试过了,还是连不上
右边是我的数据库
是连接字符串不对还是什么?都搞一天了还没搞定
------解决方案--------------------
_com_error里面错误信息是?
------解决方案--------------------
HRESULT hr = m_pConnection.CreateInstance("ADODB.Connection");
看一下hr成功否
另外是否初始化ole?
------解决方案--------------------