判断WINCC是否连接远程ORACLE数据库,连接上就写入,连接不上就写入本地文件 ,再通过另一个全局动作判断连接,连接后将本地文件的数据写入远程数据库。以下代码只是连接数据库和写入,因网络经常出现问题不能写入,数据丢失。
Option Explicit
Function action
Dim objConnection
Dim strConnectionString
Dim wendu
Dim da
Dim strSQL
Dim objCommand
Dim sc
strConnectionString = "Provider=MSDASQL;DSN=gbrs;UID=system;PWD=xbc;"
wendu = HMIRuntime.Tags("wendu").Read
sc = HMIRuntime.Tags("sc").Read
If sc Then
strSQL = "INSERT INTO GB_RSWD (wendu) VALUES ('" & wendu & "');"
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
End If
End Function