搬家第一天-2.WinccV7.3 使用VBS判断数据库Mydatabase是否存在
作者:互联网
从某浪开始搬家,第二篇
使用wincc时,如果需要判断附带的sql server是否有某个数据库,可以使用下面的代码,实际上这个应该属于IT行业的内容。
Sub OnClick(ByVal Item)
Dim ors,conn,con,ssql,ocom
Dim PCName
PCName=HMIRuntime.Tags("@LocalMachineName").Read
con="Provider = SQLOLEDB.1;password = sa;user id = sa;Initial Catalog =master;Data Source = " & PCName & "\WINCC"
''con="Provider = SQLOLEDB.1;password = sa;user id = sa;Data Source = " & PCName & "\WINCC"
Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString=con
conn.Cursorlocation=3
conn.open
ssql="select * from master.dbo.sysdatabases where [name] ='MyDataBase'"
''ssql="select Name from dbo.sysdatabases where Name ='MyDataBase'"
Set ors=CreateObject("ADODB.RecordSet")
Set ocom=CreateObject("ADODB.Command")
Set ocom.activeconnection=conn
ocom.CommandType=1
ocom.CommandText=ssql
Set ors=ocom.Execute
If ors.recordcount>0 Then
Msgbox "MyDataBase已经存在,无需创建"
Else
Msgbox "MyDataBase不存在"
End If
Set ors=Nothing
conn.close
Set conn=Nothing
End Sub
标签:Set,WinccV7.3,Mydatabase,MyDataBase,ors,VBS,ADODB,sa,conn 来源: https://www.cnblogs.com/fishingsriver/p/14342880.html