0% found this document useful (0 votes)
2K views

WinCC OLEDB Connection String

This document contains VBScript code that connects to a SQL Server database, runs a SQL query to select all database names that start with "CC", and outputs the results. It first defines connection and recordset objects, specifies the connection string, opens the connection, defines and executes the SQL command, checks for returned fields, and loops through outputting each database name before closing the connection.

Uploaded by

rigo_sk
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

WinCC OLEDB Connection String

This document contains VBScript code that connects to a SQL Server database, runs a SQL query to select all database names that start with "CC", and outputs the results. It first defines connection and recordset objects, specifies the connection string, opens the connection, defines and executes the SQL command, checks for returned fields, and loops through outputting each database name before closing the connection.

Uploaded by

rigo_sk
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Provider: WinCCOLEDBProvider.1 LocMachineName = HMIRuntime.Tags("@LocalMachineName").Read strConnectionString = "Provider=SQLOLEDB.

1;Integrated Security=SSPI;Persist Sec urity Info=False;Initial Catalog=master;Data Source=" & LocMachineName & "\WINCC " strSQL = "SELECT RTRIM(name) as dbname FROM sysdatabases WHERE name LIKE 'CC%'" Set objConnection = CreateObject("ADODB.Connection") objConnection.ConnectionString = strConnectionString objConnection.Open Set objRecordset = CreateObject("ADODB.Recordset") Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection objCommand.CommandText = strSQL Set objRecordset = objCommand.Execute lngCount = objRecordset.Fields.Count HMIRuntime.Trace lngCount & vbNewLine If (lngCount>0) Then objRecordset.movefirst For i = 0 To objRecordset.Fields.Count HMIRuntime.Trace objRecordset.Fields(0).Value & vbNewLine objRecordset.movenext Next Else HMIRuntime.Trace "Selection returned no fields" & vbNewLine End If Set objCommand = Nothing objConnection.Close Set objRecordset = Nothing Set objConnection = Nothing

You might also like