1. 防火墙必须配置为允许1433端口为引入端口,以及1024-65535为外出端口
2. 连接字符串必须指定SQL Server地址:IP地址,服务器DNS名字或host文件里的名字
3. 连接字符串应当指定Network Library类型,在这种情况下"dbmssocn" (没有引号)为TCP/IP Sockets Net-Library
在下面的例子代码中, servername应当为服务器DNS名字, IP 地址,或hosts文件中的名字:
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