Connect VC ++ to the SQL Server database (Remote + local)

Source: Internet
Author: User
Connect to the remote database sqlserver2005
Cstring strconn =_ T ("driver = {SQL Server}; server = 192.168.57.49, 1433; database = data name; uid = user name; Pwd = password "); (Driver = {SQL native client} is a string connecting to the local database. An error occurs when connecting to the remote database)
Connect to local database
Sqlserver2005
Cstring strconnserver2005 = _ T ("provider = sqloledb.1; persist Security info = false; initial catalog = databasename; Data Source = 127.0.0.1 ");
Sqlserver2008
Cstring strconnserver2008 = _ T ("provider = sqloledb.1; Integrated Security = sspi; persist Security info = false; initial catalog = databasename; Data Source =. \ Sqlexpress; User id = username; Password = password ;");
Pass the test (. \ Sqlexpress escape \ depends on the situation, because it is placed in the string, so you need )
 M_pconnection-> open (_ bstr_t (strconn), _ bstr_t (struserid), _ bstr_t (strpassword), admodeunknown );
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.