我正在尝试将我的一个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, 烫发