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