如题,在深入浅出WinCC 中有讲到用WinCC OLE DB读取过程值归档的方法,具体方法可见图片1,代码如下,但是运行VB应用程序,总是提示:
ConnectionOpen (ParseConnectParams())无效的连接,不知问题出在哪?代码按书上例子只对连接字符串做了相应修改,或者问题在于WinCC ConnectivityPack 的安装上,ConnectivityPack Server 装不上,只装得上Client
Private Sub Command1_Click()
Dim sPro As String
Dim sDsn As String
Dim sSer As String
Dim sCon As String
Dim sSql As String
Dim conn As Object
Dim oRs As Object
Dim oCom As Object
Dim oItem As ListItem
Dim m, n, s
'#为ADODB创建connection string'
sPro = "Provider = WinCCOLEDBProvider.1;"
sDsn = "Catalog = CC_Archive_13_10_28_16_21_21R;"
'sSer = "Data Source = .\WinCC" '
sSer = "Data Source = QINJIWEN:\WinCC"
sCon = sPro + sDsn + sSer
'#在sSql定义命名文本(相对时间)'
sSql = "TAG:R,'3','0000 - 00 - 00 00:10:00.000','0000 - 00 - 00 00:00:00.000'"
MsgBox "Open with:" & vbCr & sCon & vbCr & sSql & vbCr
'建立连接'
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = 3
conn.Open
'#使用命令文本进行查询'
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
'#填充记录集'
Set oRs = oCom.Execute
m = oRs.Fields.Count
'#用记录集填充标准listview对象'
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields(1).Name), 140
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields(2).Name), 70
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields(3).Name), 70
If (m > 0) Then
oRs.MoveFirst
n = 0
Do While Not oRs.EOF
n = n + 1
s = Left(CStr(oRs.Fields(1).Value), 23)
Set oItem = ListView1.ListItems.Add()
oItem.Text = Left(CStr(oRs.Fields(1).Value), 23)
oItem.SubItems(1) = FormatNumber(oRs.Fields(2).Value, 4)
oItem.SubItems(2) = Hex(oRs.Fields(3).Value)
If (n > 1000) Then Exit Do
oRs.MoveNext
Loop
oRs.Close
Else
End If
Set oRs = Nothing
conn.Close
Set conn = Nothing
End Sub
图片说明:
最佳答案
可以参考一下:《使用 WinCC OLE DB Provider 导出 WinCC / CAS 归档数》
http://blog.sina.com.cn/s/blog_669692a60100quuc.html
提问者对于答案的评价:
very good!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc219401.html