English 中文(简体)
VBS 错误, 不能使用 WMI 服务执行查询吗?
原标题:VBS Error, Can t execute a query using WMI Service?

我得到 不正确的语法接近)

它所引用的线是 oCN.Execute(sQL) 指向终点。

相互操作上,如果我删除 中的每一条线 < code> 中的每一条collects 项中的任何一行,它不会出错。

无法使用 WMI 服务对象执行 SQL 查询吗? 还是我在别处出错?

我可以应请求列出更多的代码; Im 尽量保持简单。

Set oCN = CreateObject("ADODB.connection")
sCN =  "Provider=SQLOLEDB; Data Source=" & oRS("sql_server_instance") & ";Initial Catalog=master;Integrated Security=SSPI;"
oCN.Open sCN

 Gather disk information from WMI Service
Set oWMIService = GetObject("winmgmts:\" & oRS("sql_server") & "
ootcimv2")
Set colItems = oWMIService.ExecQuery _
    ("Select * From Win32_Volume")

 Loop through all disks    
For Each objItem in colItems

sSQL="insert into HDS_DBA_DB.[dbo].[TEMP_disk_info_table] (drive_letter, capacity) " &_
"values( " & objItem.DriveLetter & " ," & objItem.Capacity & ")"

oCN.Execute(sSQL)

Next
最佳回答

问题似乎在于 objitemot.capital 属性中。 能力 属性, 在插入之前检查此属性的值, 因为值可以是空的, 并产生错误的 SQL 句子, 如

insert into HDS_DBA_DB.[dbo].[TEMP_disk_info_table] (drive_letter, capacity) values ( E: ,)
问题回答

我相信在 ADODB 上使用. Execute 。 连接对象是为了获取结果 。

您是否尝试过使用 ADODB. command 对象?

Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = oCN

cmd.CommandType = 1
cmd.CommandText = sSQL

cmd.Execute();




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签