ADO connecting to SQL Server

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.