Ado connects to SQL server and adosqlserver

Source: Internet
Author: User

Ado connects to SQL server and adosqlserver

// Add the following sentence to the SQL server connection header file of ado: # import "C: \ Windows \ system \ msado15.dll" no_namespace rename ("EOF", "rsEOF ")
</Pre> <pre code_snippet_id = "620722" snippet_file_name = "blog_201501__3_721_60" name = "code" class = "cpp"> // CoInitialize (NULL) in cpp ); _ ConnectionPtr pConn (_ uuidof (Connection); _ RecordsetPtr pRst (_ uuidof (Recordset); _ CommandPtr pCmd (_ uuidof (Command )); try {// here is the entry from windows authentication. the SQL server authentication is also debugged on my host pConn-> ConnectionString = "Provider = SQLOLEDB.1; integrated Security = SSPI; Persist Security Info = False; Ini Tial 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; "; // the field in the comment that must contain pConn-> Open ("","", "", AdConnectUnspecified); // open the connection pRst = pConn-> Execute ("select * from [dbo]. [user] ", NULL, ad1_text); // read the 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 number of current records pRst-> MoveNext ();}} catch (_ com_error e) // catch exceptions {CString errormessage; errormessage. format ("failed to connect to the database! \ R \ n error message: % s ", e. errorMessage (); AfxMessageBox (errormessage); // display the error message return;} pRst-> Close (); pConn-> Close (); pCmd. release (); pRst. release (); pConn. release (); CoUninitialize ();

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.