如何wincc中使用VBS脚本读写SQLServer数据库文件?

新建一个wincc项目,想要在其后台数据库中间建立表格,通过VBS脚本对该数据库进行读写操作,该如何做?

最佳答案

Dim connstr
connstr = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=CC_JZX_WINC_13_03_06_10_00_07R;Data Source=.\WINCC;uid=sa;pwd=;"
Set MyConn = CreateObject("ADODB.Connection")
    With MyConn
       .ConnectionString = connstr
       .CursorLocation = 3
       .Open
    End With
 Dim strSQL
 Dim rsTmp
    strSQL = "数据库操作语句"
    Set rsTmp = CreateObject("ADODB.Recordset")
    Set rsTmp.ActiveConnection = MyConn
    With rsTmp
       .CursorLocation = 3 
       .CursorType = 3 
       .LockType = 1
       .Source = strSQL
       .Open
    End With
刚学着弄完,Persist Security Info=False;这条语句害我研究了很久,之前没有太在意,导致远程读取时登录失败
参考资料:http://www.ad.siemens.com.cn/service/answer/tobe_solution.aspx?Q_ID=109096&cid=1032

提问者对于答案的评价:
非常感谢你的回答。
但对于“Initial Catalog=CC_JZX_WINC_13_03_06_10_00_07R”这一句我不太明白,如何知道我所做项目对应数据库名?

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc217278.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2017年11月26日
下一篇 2017年11月26日

相关推荐