ADO connect the SQL server//header file with the following sentence, #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 is also debugged on my machine 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; /Note the representation must contain the fields 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