在使用vb6.0连接到wincc历史数据库的过程中出现了一些问题,不能解决,故此致信求助!使用wincc版本是6.0SP3亚洲版.sql是2000 sp5.
vb代码如下:在窗体上添加按钮,然后点击事件中如下:
sPro = "Provider=WinCCOLEDBProvider.1;" '//定义服务提供者
sDsn = "Catalog=CC_fanghua_09_09_28_16_41_49R;"
sSer = "Data Source=.\WinCC"
SCON = sPro + sDsn + sSer
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = SCON
conn.CursorLocation = 3
conn.Open
sSql = "TAG:R,'speed1\c_speed1_1','2009-09-24 09:19:00.000','2009-09-24 09:20:00.000'"
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
Set oRs = oCom.Execute
程序点击运行后出现错误:
实时错误“-2147467259(80004005)”
cannot open database requested in login 'cc_fanghua_09_09_28_16_41_49R'.login fails.
希望能给予解决,万分感谢!
最佳答案
脚本看来没什么错误.提示错误是数据库登录失败,所以先确认'cc_fanghua_09_09_28_16_41_49R'是否写错了,然后确定你是查本机数据库还是网络其他电脑数据库,把".\WinCC"换成是"计算机名字.\wincc"试试,".\WinCC"只是查本机数据库的.还有就是wincc要运行才能查询.
我这里有个例子,你可以参考一下:
Dim cnn As String
cnn = "provider=WinCCOLEDBProvider.1;catalog=CC_gz_food_09_07_14_14_54_22R;data source=wincc01\WinCC"
dim cc1 as object
Set cc1 = CreateObject("adodb.connection")
cc1.ConnectionString = cnn
cc1.CursorLocation = 3
cc1.Open
Dim rst As Object
Set rst = CreateObject("adodb.recordset")
Dim ssql As String
ssql = "TAG:R,'speed1\c_speed1_1','2009-09-24 09:19:00.000','2009-09-24 09:20:00.000'"
rst.Open ssql, cc1
rst.MoveFirst
cc1.Close
Set cc1 = Nothing
Set rst = Nothing
提问者对于答案的评价:
很好,谢谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc270713.html