主题:vc6.0连接sql2000出错了!!!!!!
[color=0000FF]我尝试用ado的方式连接sql2000数据库,代码如下:[/color]
::CoInitialize(NULL);
try
{
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
CString strConnectTmp;
strConnectTmp.Format ("Provider=SQLOLEDB;Server=.;Database=test;uid=sa;pwd=123");
_bstr_t strConnect=strConnectTmp;
m_pConnection->Open(strConnect,"","",adModeUnknown);
AFXMessageBox("连接成功!");
}
catch(_com_error e)
{
AFXMessageBox(e.Description());
}
[color=FF0000][color=C0C0C0][color=FF0000][color=0000FF][color=FF0000] 在这之前,我已经引入了msado15.dll,但是编译的时候出现下面的错误:[/color][/color][/color][/color][/color]
:\vc\ConnDB\ConnDBDlg.cpp(182) : error C2065: '_ConnectionPtr' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(182) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
F:\vc\ConnDB\ConnDBDlg.cpp(182) : error C2065: 'm_pConnection' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(183) : error C2228: left of '.CreateInstance' must have class/struct/union type
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2065: '_bstr_t' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2146: syntax error : missing ';' before identifier 'strConnect'
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2065: 'strConnect' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
F:\vc\ConnDB\ConnDBDlg.cpp(187) : error C2227: left of '->Open' must point to class/struct/union
F:\vc\ConnDB\ConnDBDlg.cpp(187) : error C2065: 'adModeUnknown' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(188) : error C2065: 'AFXMessageBox' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(190) : error C2061: syntax error : identifier '_com_error'
F:\vc\ConnDB\ConnDBDlg.cpp(190) : error C2310: catch handlers must specify one type
F:\vc\ConnDB\ConnDBDlg.cpp(192) : error C2065: 'e' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(192) : error C2228: left of '.Description' must have class/struct/union type
F:\vc\ConnDB\ConnDBDlg.cpp(195) : error C2317: 'try' block starting on line '181' has no catch handlers
Generating Code...
执行 cl.exe 时出错.
Creating browse info file...
ConnDB.exe - 1 error(s), 0 warning(s)
小弟才学VC,有很多东西不懂。哪位高手能告诉我这个问题怎么解决啊???
::CoInitialize(NULL);
try
{
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
CString strConnectTmp;
strConnectTmp.Format ("Provider=SQLOLEDB;Server=.;Database=test;uid=sa;pwd=123");
_bstr_t strConnect=strConnectTmp;
m_pConnection->Open(strConnect,"","",adModeUnknown);
AFXMessageBox("连接成功!");
}
catch(_com_error e)
{
AFXMessageBox(e.Description());
}
[color=FF0000][color=C0C0C0][color=FF0000][color=0000FF][color=FF0000] 在这之前,我已经引入了msado15.dll,但是编译的时候出现下面的错误:[/color][/color][/color][/color][/color]
:\vc\ConnDB\ConnDBDlg.cpp(182) : error C2065: '_ConnectionPtr' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(182) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
F:\vc\ConnDB\ConnDBDlg.cpp(182) : error C2065: 'm_pConnection' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(183) : error C2228: left of '.CreateInstance' must have class/struct/union type
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2065: '_bstr_t' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2146: syntax error : missing ';' before identifier 'strConnect'
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2065: 'strConnect' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(186) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
F:\vc\ConnDB\ConnDBDlg.cpp(187) : error C2227: left of '->Open' must point to class/struct/union
F:\vc\ConnDB\ConnDBDlg.cpp(187) : error C2065: 'adModeUnknown' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(188) : error C2065: 'AFXMessageBox' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(190) : error C2061: syntax error : identifier '_com_error'
F:\vc\ConnDB\ConnDBDlg.cpp(190) : error C2310: catch handlers must specify one type
F:\vc\ConnDB\ConnDBDlg.cpp(192) : error C2065: 'e' : undeclared identifier
F:\vc\ConnDB\ConnDBDlg.cpp(192) : error C2228: left of '.Description' must have class/struct/union type
F:\vc\ConnDB\ConnDBDlg.cpp(195) : error C2317: 'try' block starting on line '181' has no catch handlers
Generating Code...
执行 cl.exe 时出错.
Creating browse info file...
ConnDB.exe - 1 error(s), 0 warning(s)
小弟才学VC,有很多东西不懂。哪位高手能告诉我这个问题怎么解决啊???