我正在尝试将我的 VBS 脚本之一从使用 SQLOLEDB 切换到 ODBC 驱动程序。这么久一切都像预期的那样工作 - 除了一件事:
从 MSSQL 实例获取SERVERPROPERTY("is_clustered")时,使用每个驱动程序的结果值不同。
这是示例脚本的输出(脚本如下):
C:\> cscript test.vbs Provider: sqloledb is_clustered (name): is_clustered is_clustered (type): 12 is_clustered (value): 0 Driver: (SQL Server) is_clustered (name): is_clustered is_clustered (type): 204 C:\test.vbs(33, 1) Microsoft VBScript runtime error: Type mismatch
有谁知道我做错了什么或我的代码中缺少什么?
哦,是的,代码......这是示例脚本本身:
Option Explicit
Dim RS, CONN1, CONN2
Set RS = CreateObject("ADODB.Recordset")
Set CONN1 = CreateObject("ADODB.Connection")
CONN1.ConnectionTimeout = 2
CONN1.Provider = "sqloledb"
CONN1.Properties("Integrated Security").Value = "SSPI"
CONN1.Properties("Data Source").Value = "HOSTNAME\INST01"
CONN1.Open
WScript.echo "Provider: sqloledb" & vbLf
RS.Open "SELECT SERVERPROPERTY('IsClustered') AS is_clustered", CONN1
WScript.echo "is_clustered (name): " & RS.fields(0).Name
WScript.echo "is_clustered (type): " & RS.fields(0).Type
WScript.echo "is_clustered (value): " & RS("is_clustered") & vbLf
RS.Close
Set CONN2 = CreateObject("ADODB.Connection")
CONN2.ConnectionTimeout = 2
CONN2.ConnectionString = "driver={SQL Server};" & _
"server=HOSTNAME\INST01;" & _
"Trusted_Connection=yes"
CONN2.Open
WScript.echo "Driver: (SQL Server)" & vbLf
RS.Open "SELECT SERVERPROPERTY('IsClustered') AS is_clustered", CONN2
WScript.echo "is_clustered (name): " & RS.fields(0).Name
WScript.echo "is_clustered (type): " & RS.fields(0).Type
WScript.echo "is_clustered (value): " & RS("is_clustered")
RS.Close
提前谢谢了!
BR,马塞尔