我通过VB动作脚本定时(1分钟)将WINCC界面上的数据传送至ACCESS数据库(access数据库的数据表链接至远程SQL服务器)。
但现在发现该动作脚本经常会死,不再传送数据至ACCESS,但wincc还是在正常运行。
当退出WINCC时,进度条往往卡在全局脚本。
当重启系统时,又能正常传送数据了。
这种问题一直困扰着我,不知道如何解决。
附VB脚本如下。
另外,各位高手如有直接连接远程SQL服务器的脚本,请不吝赐教!
Option Explicit
Function action
Dim objConnection
Dim strConnectionString
Dim raTankPv
Dim raReflux
Dim raCurrent
Dim raSpeed
Dim raFlow
Dim raWeight
Dim raWaterPv
Dim raWaterSp
Dim raWaterLmn
Dim raTank101Sp
Dim raTank101Lmn
Dim raTank103Sp
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;"
raTankPv = HMIRuntime.Tags("TIC258/101.PV_IN").Read
raReflux = HMIRuntime.Tags("TT_meas/R258_TI_103.U").Read
raCurrent = HMIRuntime.Tags("AT_meas/R258_AI_101.U").Read
raSpeed = HMIRuntime.Tags("ST_meas/R258_SI_101.U").Read
raFlow = HMIRuntime.Tags("FT_meas/R258_FI_101.U").Read
raWeight = HMIRuntime.Tags("WT_meas/R258_WI_101.U").Read
raWaterPv = HMIRuntime.Tags("TIC258/102.PV_IN").Read
raWaterSp = HMIRuntime.Tags("TIC258/102.SP").Read
raWaterLmn = HMIRuntime.Tags("TIC258/102.LMN").Read
raTank101Sp = HMIRuntime.Tags("TIC258/101.SP").Read
raTank101Lmn = HMIRuntime.Tags("TIC258/101.LMN").Read
raTank103Sp = HMIRuntime.Tags("TIC258/103.SP").Read
strSQL = "INSERT INTO R258 (tankPv,REFLUX,CURRENT,SPEED,FLOW,WEIGHT,tank101Sp,tank101Lmn,tank103Sp,waterPv,waterSp,waterLmn) VALUES (" & raTankPv & "," & raReFlux & "," & raCurrent & "," & raSpeed & "," & raFlow & "," & raWeight & "," & raTank101Sp & "," & raTank101Lmn & "," & raTank103Sp & "," & raWaterPv & "," & raWaterSp & "," & raWaterLmn & ");"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Functi
问题补充:
我就是要每隔一分钟记录一次数据,那VBS如何释放呢?
最佳答案
1、如果VBS脚本经调试后可正确无误的访问MS_ACCESS数据库,则就可确认VBS脚本代码是正确无疑了!
2、需要提醒的是MS_ACCESS是小型单机数据库,数据库文件在大于20MB后,打开后读/写访问的速度将明显降低,甚至进入死机状态。这我可有亲身使用经历。
3、当MS_ACCESS数据库文件随读/写访问容量的增加而达到一定极限后,就应将该数据库文件中数据做备份保存,然后在删除该文件中的数据,以减轻数据库文件的容量,从而才能加快读/写访问该数据库的速度。
4、所以,需要仔细查看一下MS_ACCESS数据库文件的容量是否超载!
提问者对于答案的评价:
只能给你了
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc266737.html