我这边电脑安装了WinCC V7.2 版本, 在自带的SQLServer 中建立了一个数据库,并且在电脑的ODBC 的用户DSN 和系统DSN中,都添加了该数据库,并在添加的时候,测试连接成功。我在脚本中编了程序,用来查询,但是不成功,具体的程序如下:
Dim A_AirTest_Pro
Dim cn
Dim rst
Dim rstCom
Dim strcn
Dim objItem
Dim strsql
A_AirTest_Pro= HMIRuntime.Tags("Air_Program_No_01").Read
HMIRuntime.Tags("Air_Fill_Time_01").Write 0.0
HMIRuntime.Tags("Air_Steady_Time_01").Write 0.0
HMIRuntime.Tags("Air_Check_Time_01").Write 0.0
HMIRuntime.Tags("Air_Fill_Press_01").Write 0.0
HMIRuntime.Tags("Air_Steady_Press_01").Write 0.0
HMIRuntime.Tags("Air_Check_Press_01").Write 0.0
HMIRuntime.Tags("Air_Process").Write "Data Read Finsh"
'strcn = "Data Source=Test_01;UID='';PWD='';"
strcn = "Data Source=Test_01;UID=shc30053;PWD=shc30053;"
Set cn = CreateObject("ADODB.connection")
cn.ConnectionString = strcn
cn.Open
HMIRuntime.Tags("Air_Process").Write "Sql Server connection"
strsql = "SELECT * FROM Air_Leak_Test Where Program_No ="&A_AirTest_Pro&""
HMIRuntime.Tags("Air_Process").Write "Sql Server connection_01"
Set rst = CreateObject("ADODB.Recordset")
HMIRuntime.Tags("Air_Process").Write "Sql Server connection_02"
Set rstCom = CreateObject("ADODB.Command")
HMIRuntime.Tags("Air_Process").Write "Sql Server connection_03"
rstCom.CommandType=1
HMIRuntime.Tags("Air_Process").Write "Sql Server connection_04"
Set rstCom.ActiveConnection = cn
HMIRuntime.Tags("Air_Process").Write "Sql Server connection_05"
rstCom.CommandText = strsql
HMIRuntime.Tags("Air_Process").Write "Sql Server connection_06"
Set rst = rstCom.Execute
'rstCom.Execute
HMIRuntime.Tags("Air_Process").Write "Sql command execute"
If Not rst.eof Then
rst.MoveFirst
HMIRuntime.Tags("Air_Fill_Time_01").Write rst.Fields(0).value
HMIRuntime.Tags("Air_Steady_Time_01").Write rst.Fields(1).value
HMIRuntime.Tags("Air_Check_Time_01").Write rst.Fields(2).value
HMIRuntime.Tags("Air_Fill_Press_01").Write rst.Fields(3).value
HMIRuntime.Tags("Air_Steady_Press_01").Write rst.Fields(4).value
HMIRuntime.Tags("Air_Check_Press_01").Write rst.Fields(5).value
End If
rst.close
cn.close
Set rst=Nothing
Set cn=Nothing
程序走到
Set rst = rstCom.Execute 这里不走了,也就是说,该语句并没有执行。但是以上的代码在WinCC V7.0 中是可以执行的。不知道为什么在7.2 中就执行不下去。希望大家帮忙解答一下。多谢了!
二者的区别,我看了一下,7.0 装在32位的操作系统Win7 企业版 SP1 .7.2 装在64位的操作系统Win7 企业版SP1。