用VB全局脚本每分钟将数据传送至ACCESS,一直没有问题,但最近却发现偶尔会无法将数据传送至ACCESS,也任何提示,重启后问题消失。。
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
最佳答案
看不出什么问题,如果你的程序以前一直运行正常,而现在出了问题的话,最好找一下其他原因。
另外你可以试一试将你的ACCESS拷贝一份出来,将数据清空,然后用这个程序往里边插入数据看情况如何
提问者对于答案的评价:
谢谢!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc267620.html