用OLE DB访问WINCC6.2过程值归档,调试结果提示:[DBNETLIB][CONNECTIONOPEN()).]SQL SERVER DOES NOT EXIST OR ACCESS DENIED.错误,若按照书上的代码,则提示:[DBNETLIN]CONNECTIONOPEN(INVALID CONNECTION()).]INVALID CONNECTION.请帮我看看问题出在哪里?源代码如下:
Private Sub EXECUTE_Click()
Dim sPro As String
Dim sDsn As String
Dim sSer As String
Dim sCon As String
Dim sSql As String
Dim sUID As String
Dim sPwd As String
Dim sIniCata As String
Dim conn As Object 'ADODB.Connection
Dim oRs As Object 'ADODB.Recordset
Dim oCom As Object 'ADODB.Command
Dim oItem As ListItem
Dim m, n, s
sPro = "Provider='WINCCOLEDBProvider';"
sDsn = "Catalog='CC_Win_T_09_06_24_10_09_58R';"
sSer = "Data Source='TUOWEI-CH\WINCC'"
sCon = sPro + sDsn + sSer
sSql = "TAG:R,'PVArchive\Tag_1','2009-06-28 09:00:00.000','2009-06-30 11:00:00.000'"
'MsgBox"Open With:" &vbCr & sCon & vbCr & sSql &vbCr Persist Security Info=False; user id=;password=;
'Provider=SQLOLEDB.1;Password=tuoweiautomatic;Persist Security Info=True;User ID=sa;Initial Catalog=CC_suidao_09_06_24_09_42_34R;Data Source=TUOWEI-CH\wincc
Set conn = CreateObject("ADODB.Connection") 'T_09_06_"
conn.ConnectionString = "Provider=WinCCOLEDBProvider.1;Data Source=CC_Win_T_09_06_24_10_09_58R;Catalog=TUOWEI-CH\wincc;User ID=sa;Password=;"
'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
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields.Item(1).Name), 140
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields.Item(1).Name), 70
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields.Item(1).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) = FormatNumber(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
MsgBox "Open With:"
End Sub
专家建议
请参考
http://www.ad.siemens.com.cn/download/searchResult.aspx?searchText=A0048
A0048“WinCC V6 使用技巧”演示项目及使用说明(2006.08.18)
DemoV6画面PA7_bld04.pdl,PA7_bld05.pdl中vbs访问变量归档的方法
提问者对于答案的评价:
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc311105.html