搬家第一天4.WinccV7.3删除数据库mydatabase

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
   ssql="drop Database MyDatabase"
   ocom.CommandText=ssql
   Set ors=ocom.Execute
   Msgbox "MyDatabase删除完毕"
Else
  Msgbox "MyDataBase不存在,无需删除"


End If
Set ors=Nothing
conn.close
Set conn=Nothing
End Sub

上一篇:检查SQL注入攻击中的数据库


下一篇:mysql备份和还原