VC remote database access

Source: Internet
Author: User

If it is an external IP address, the following
Strsql = "provider = sqloledb; server = gooyan; database = skillsbox; uid = sa; Pwd = aaaaaaaa ";
Change server to IP address.
The LAN can be an IP address or a machine name.
Follow these steps
1. Add stdafx. h
# Import "C: \ Program Files \ common files \ System \ ADO \ msado15.dll" no_namespace Rename ("EOF", "adoeof ")
2. Add the initinstance in the app file
If (s_ OK! = Oleinitialize (null ))
{
Afxmessagebox ("COM Component Library initialization error ");
}

The following are database operations.
_ Connectionptr pconn;
_ Recordsetptr PRS;
Cstring strsql;
Pconn. createinstance (_ uuidof (connection ));
Pconn-> cursorlocation = aduseclient;
Strsql = "provider = sqloledb; server = gooyan; database = skillsbox; uid = sa; Pwd = aaaaaaaa ";
Pconn-> open (_ bstr_t (strsql), "", "",-1 );

PRS. createinstance (_ uuidof (recordset ));
PRS-> cursorlocation = aduseclient;
PRS-> putactiveconnection (pconn. getinterfaceptr ());

Prs1.createinstance (_ uuidof (recordset ));
Prs1-> cursorlocation = aduseclient;
Prs1-> putactiveconnection (pconn. getinterfaceptr ());

Strsql = "select * From catalog order by cataid ";
PRS-> open (_ bstr_t (strsql), vtmissing, adopendynamic, adlockbatchoptimistic, adshorttext );

 

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.