Add the following sentence to the ADO connection SQL server//header file. #import "C:\Windows\system\msado15.dll" no_namespace rename ("EOF", "rseof")
</pre><pre code_snippet_id= "620722" snippet_file_name= "blog_20150316_3_7210460" name= "code" class= "CPP" >//cpp inside CoInitialize (NULL), _connectionptr pconn (__uuidof (Connection)); _RecordsetPtr pRst (__uuidof (Recordset)) ; _commandptr Pcmd (Command) try{//The following is entered from Windows authentication. SQL Server Authentication on my machine also for debugging out pconn->connectionstring= "provider=sqloledb.1;integrated Security=sspi; Persist Security info=false;initial catalog=test;data source=win7-20120101na\\sqlexpress; Use Procedure for prepare=1; Auto translate=true; Packet size=4096; Workstation Id=win7-20120101na; Use encryption for Data=false; Tag with column collation when Possible=false ";//pconn->connectionstring=" provider=sqloledb.1;integrated Security =sspi;initial Catalog=test;data source=win7-20120101na\\sqlexpress; /gaze in the expression must include the field Pconn->open ("", "", "" ", adconnectunspecified); Open Connection Prst=pconn->execute ("select * FROM [dbo].[ User] ", null,adcmdtext); Read User table _variant_t Vusername;while (!prst->rseof) {vUserName=prst->getcollect ("id"); CString Message;message. Format ("%s", (LPCTSTR) (_bstr_t) vusername); AfxMessageBox (message);///Display the current record number Prst->movenext ();}} catch (_com_error E)///catch Exception {CString errormessage;errormessage. Format ("Connection database failed!\r\n error message:%s", E.errormessage ()); AfxMessageBox (errormessage);///Display error message return;} Prst->close ();p conn->close ();p cmd.release ();p rst.release ();p conn.release (); CoUninitialize ();
ADO connecting to SQL Server