Using ADO to connect to SQL Server behind a firewall

Source: Internet
Author: User
Tags connect firewall
ado|server| Firewall
1. The firewall must be configured to allow port 1433 to be introduced, and 1024-65535 for outgoing ports

2. The connection string must specify the SQL Server address: IP address, server DNS name, or name in the host file

3. The connection string should specify the network Library type, in which case "dbmssocn" (without quotes) is a TCP/IP Sockets net-library

In the example code below, the servername should be the server DNS name, IP address, or name in the Hosts file:

Set Conn = CreateObject ("ADODB. Connection ")

Set Rs = CreateObject ("ADODB.") Recordset ")

Set Cmd = CreateObject ("Adodb.command")

Conn.Open "PROVIDER=SQLOLEDB; Password=password; Persist Security info=true; User id=username;initial Catalog=dbname;data Source=servername; Network LIBRARY=DBMSSOCN "

Cmd.activeconnection=conn

SQL = "SELECT * FROM TABLE"

Cmd.commandtext = SQL

Set Rs = Cmd.execute


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.