Binding SQL Server Records to a WinCC Professional 15.1 Grid
WinCC Professional 15.1, the HMI engineering component of the TIA Portal V15.1 release, is intentionally not a general-purpose .NET host. Its screen editor exposes HMI-grade controls only, and a Windows Forms DataGrid or WPF DataGrid is not one of them. Engineers who need to display a SQL Server recordset on a runtime face a recurring set of symptoms: a third-party ActiveX grid vanishes or becomes uneditable after the first TIA Portal restart, a bound Recordset compiles without errors and renders nothing, or a VBScript routine that opens an ADODB recordset runs cleanly but the control refuses to consume the rows. This reference explains why those approaches fail, documents the two real options that exist in the Siemens product line for displaying tabular SQL data in a WinCC Professional runtime, and provides working connection strings, VBScript patterns, parameter tables, and a troubleshooting matrix that maps the most common symptoms to root cause and remediation.
1. Problem Definition: Why "Drop a DataGrid on the Screen" Does Not Work
Engineers typically arrive at this problem by translating a desktop .NET or VB6 pattern onto a WinCC screen. In a desktop application the workflow is:
- Add a
DataGridorDataGridViewto the form. - Open an
ADODB.Connectionin code. - Open an
ADODB.Recordsetagainst a SQL statement. - Assign the recordset to the grid's
DataSource(or setDataSource = rsandDataMemberaccordingly).
Step 4 is the one that fails in WinCC Professional. The HMI screen is not a System.Windows.Forms.Form. The screen object model exposed to VBScript is a stripped-down HMI container that knows about HMI tags, language switches, screen windows, and the HMI-specific controls registered against the WinCC Runtime process. A System.Windows.Forms.DataGrid instantiated inside that container cannot subscribe to the WinCC HMI tag subsystem, and the screen's Properties dialog will not expose DataSource as a configurable property.
The behavior observed in the field falls into three buckets:
| Symptom | Where it appears | Root cause |
|---|---|---|
| ActiveX DataGrid renders empty rows on first run, then refuses to repaint after TIA restart | MSFlexGrid, MSHFlexGrid, VB6 DataGrid | ActiveX registered for the editor process but not the WinCC Runtime process; runtime reverts to uneditable state |
ADODB.Recordset opens without error but no row appears in the grid |
Any custom OLE container | WinCC VBScript has no System.Data.DataTable in scope; recordset cannot be bound |
| Screen compiles, deploys, opens, then closes immediately on first click of the grid | Third-party .NET controls dropped as ActiveX wrapper | WinCC Runtime is a 64-bit process on 64-bit panels/PCs starting in V15.1; mismatched bitness of the control's host DLL |
None of these are bugs in the sense of a Siemens defect: they are the result of treating the HMI screen editor as a desktop form designer. The fix is to use a control that Siemens has registered against the WinCC Runtime process.
2. The Two Real Options
Within the Siemens product line, two options exist for showing a row-and-column dataset on a WinCC Professional 15.1 screen:
| Option | License | Best fit | Limitations |
|---|---|---|---|
| Table View (RT Professional) | Included with WinCC Professional | Process value tables, alarm logs, tag logging tables, a fixed set of columns updated by the runtime | Not a free-form SQL grid; columns and data source are configured at design time |
| PM-GRID Control | PM Options, separately licensed | Free-form SQL Server grids, master/detail, user-editable rows, sorting/filter UI | Cost; configuration tooling lives in the PM Options add-on |
The Table View is documented in the TIA Portal help at Table view (RT Professional). It is the right starting point for any project that has not yet committed to a third-party grid control.
3. Option A — Table View (RT Professional)
The Table View in WinCC RT Professional is a tabular display control purpose-built for showing process values or logged values in a table. It supports user-defined column order, column visibility, sorting, and column width. It is registered against the WinCC Runtime process and survives every TIA Portal restart by design.
3.1 What the Table View can show
- Live process values from one or more HMI tags (configured as a "process" column source).
- Archived values from a WinCC tag logging database (configured as a "logged" column source).
- Alarm log entries from the WinCC alarm subsystem (configured as an "alarm" column source).
3.2 What the Table View cannot show directly
There is no "SQL Query" column source. To populate a Table View with rows that originate from a SQL Server table outside the WinCC logging/alarm databases, you must either:
- Mirror the SQL data into HMI tags at runtime (one tag per cell or one tag per row using arrays) and configure a "process" column source, or
- Use a VBScript routine that writes the query result into the tag logging database and then read the table view from the logged source.
3.3 Wiring a SQL Query into a Process Column Source
This is the most common pattern in V15.1 projects. The pattern is:
- Define an array tag
MyGrid_Column1,MyGrid_Column2, ..., of typeStringorRealwith an upper bound equal to the expected row count. - On a screen-open event, call a VBScript that opens an
ADODB.Connection, runsSELECT col1, col2 FROM dbo.MyTable, and copies eachRecordsetrow into the corresponding tag. - In the Table View, configure a process column for each array tag and bind the column width, header, and update rate.
Example VBScript pattern, suitable for a scheduled polling routine on a 500 ms tick:
' --- File: scripts\PollSQLGrid.vbs ---
Option Explicit
Dim conn, rs, sql, i, maxRows, sCol1, sCol2, sCol3
Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = 1
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=MSOLEDBSQL;Data Source=SQLSRV01;Initial Catalog=PlantData;" & _
"User ID=hmiread;Password=<config>;TrustServerCertificate=True;"
sql = "SELECT TOP 50 BatchID, Recipe, StartTime FROM dbo.BatchLog ORDER BY StartTime DESC"
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 ' adUseClient
rs.Open sql, conn, adOpenStatic, adLockReadOnly, adCmdText
maxRows = 50
ReDim sCol1(maxRows - 1)
ReDim sCol2(maxRows - 1)
ReDim sCol3(maxRows - 1)
i = 0
Do While Not rs.EOF And i < maxRows
sCol1(i) = CStr(rs("BatchID").Value)
sCol2(i) = CStr(rs("Recipe").Value)
sCol3(i) = CStr(FormatDateTime(rs("StartTime").Value, vbShortDate) & " " & _
FormatDateTime(rs("StartTime").Value, vbShortTime))
i = i + 1
rs.MoveNext
Loop
' Trim unused slots with empty strings to avoid stale values
Dim j
For j = i To maxRows - 1
sCol1(j) = ""
sCol2(j) = ""
sCol3(j) = ""
Next
' Write back into the HMI tag array
SmartTags("MyGrid_Column1") = sCol1
SmartTags("MyGrid_Column2") = sCol2
SmartTags("MyGrid_Column3") = sCol3
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
MSOLEDBSQL is the Microsoft OLE DB Driver for SQL Server (version 18+). The legacy SQLNCLI and SQLOLEDB providers are deprecated as of WinCC V16+. Configure the connection string through a WinCC script-side variable and store credentials in the WinCC User Administration, never inline in screen scripts.
3.4 Row count, sort order, and column visibility
WinCC Professional 15.1 Table View properties (sampled from the TIA Portal object properties dialog, "Table View" → "Columns" collection):
| Property | Type | Default | Notes |
|---|---|---|---|
Name |
String | "Column_n" | Internal identifier used in VBScript via Screen.Items("TableView_1").Columns(...).Name
|
Header |
String | empty | Displayed column header; supports language switching via text IDs |
Width |
Integer (px) | 120 | Column width in pixels at runtime |
SortMode |
Enum | None | None, Ascending, Descending; runtime user-click sorting requires SortMode not equal to None |
Visible |
Bool | True | Column visibility; controlled at runtime via VBScript |
DataSource |
Tag reference | (empty) | The HMI tag (scalar or array element) that backs this column |
UpdateRate |
Integer (ms) | 1000 | Poll rate in ms; lower values load the runtime tag subsystem more heavily |
3.5 Hiding and showing columns at runtime
' Hide column 2 of TableView_1 at runtime
Dim tv
Set tv = Screen.Items("TableView_1")
tv.Columns(1).Visible = False
4. Option B — PM-GRID Control
The PM-GRID Control is the only grid control developed by Siemens for use inside a WinCC Professional (or WinCC V7.x) runtime. It is built and supported by the PM Options engineering team and is the answer that the WinCC product management gives when asked whether a DataGrid is on the roadmap. It is licensed separately and ships as a PM Options add-on. The control exposes a DataSource property that accepts a recordset-like provider, supports user-editable cells, master/detail layouts, and column reordering, and is registered against the WinCC Runtime process so it survives TIA Portal restarts without the uneditable-state regression seen with MSFlexGrid.
4.1 Where to get it
PM-GRID is delivered through PM Options, the same channel that provides PM-AGENT, PM-MES, and PM-ANALYZE. Contact your Siemens sales channel with the WinCC Professional 15.1 license number to obtain the PM Options installation media and a valid PM-GRID runtime license.
4.2 What it adds over the Table View
- Direct binding to an
ADODB.Recordsetopened in VBScript — no tag-array mirroring step. - User-editable cells with field-level validation and event hooks (
OnCellChanged,OnRowInsert,OnRowDelete). - Native master/detail and grouping views.
- Configurable column types including checkboxes, drop-downs, and image columns.
4.3 When not to use it
PM-GRID is not free, and it is overkill for the common case of "show the last 50 alarm entries in a table." If the only requirement is to display already-logged data, the Table View is the right control. PM-GRID is justified when the screen must show free-form SQL data with editing and complex cell types.
5. Why MSFlexGrid, MSHFlexGrid, and VB6 DataGrid Fail
The MSFlexGrid (and its hierarchical sibling MSHFlexGrid) is a VB6-era ActiveX control that became uneditable after a TIA restart because the control's IUnknown registration in the Windows registry is invalidated when TIA Portal rebuilds the HMI container. Specifically, the symptoms are:
| Phase | What happens to MSFlexGrid | Why |
|---|---|---|
| First run after project load | Renders, accepts input | ActiveX registered for the editor process |
| TIA Portal restart | Grid renders blank, cells become uneditable | Runtime process loads the control in a more restrictive security context; the persisted OCX state is reset |
| Re-deploy from TIA | Grid renders blank, control marked "uncompiled" | WinCC Runtime is 64-bit; the VB6 OCX is 32-bit; CLSID resolution fails on 64-bit hosts |
| Runtime upgrade (V15.1 → V17) | Control removed from toolbox | Siemens tightened the allowed ActiveX list in V17, retiring several legacy OCX IDs |
VB6 DataGrid (the one found in the "Microsoft Data Grid Control 6.0" component) has the same bitness issue. Both controls also lack a DataSource that WinCC can populate: they expect a desktop-Data binding chain (DataEnvironment + Command + Recordset) that is not present in the WinCC HMI container.
6. SQL Server Data Access in WinCC Professional VBScript
WinCC Professional 15.1 VBScript supports ADODB.Connection and ADODB.Recordset from the Microsoft Data Access Components (MDAC) stack. There is no System.Data in scope, so the VBScript patterns are the late-1990s ADO patterns, not the .NET SqlDataAdapter patterns. Three things matter for a working connection:
- Provider on the WinCC Runtime PC must match a provider installed on that PC.
- Credentials should not be hard-coded; use the WinCC User Administration or a Windows service account that the runtime runs as.
- Connection lifetime: open late, close early. WinCC Runtime does not pool ADODB connections.
6.1 OLE DB Providers Available on a Default WinCC Professional 15.1 PC
| Provider | ProgID / String | Status in V15.1 | Notes |
|---|---|---|---|
| Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL) | MSOLEDBSQL |
Recommended | Shipped separately by Microsoft; install on the runtime PC and any engineering PC that compiles the project |
| SQL Server Native Client 11.0 | SQLNCLI11 |
Supported, deprecated path | Use only if MSOLEDBSQL is not installable on the runtime |
| Microsoft OLE DB Provider for ODBC Drivers | MSDASQL |
Indirect; requires an ODBC DSN on the runtime PC | Last resort for legacy data sources that have no native OLE DB provider |
| Microsoft Jet OLE DB Provider | Microsoft.Jet.OLEDB.4.0 |
32-bit only; not present on 64-bit Windows 10/11 default | Do not use for SQL Server; sometimes used for local .mdb/.accdb mirrors |
6.2 Connection String Reference
| Scenario | Connection string | Caveats |
|---|---|---|
| SQL Server with Windows auth, default instance on a named host | Provider=MSOLEDBSQL;Data Source=SQLSRV01;Initial Catalog=PlantData;Integrated Security=SSPI; |
The WinCC Runtime service account must have read access on the target schema |
| SQL Server with SQL auth | Provider=MSOLEDBSQL;Data Source=SQLSRV01\INST01,1433;Initial Catalog=PlantData;User ID=hmiread;Password=<vault>;TrustServerCertificate=True; |
Store the password in the WinCC User Administration or an external vault; do not hard-code |
| LocalDB / SQL Express user instance | Provider=MSOLEDBSQL;Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=PlantData;Integrated Security=SSPI; |
LocalDB user instances are not supported for service-account scenarios; only suitable for engineering preview |
| Failover partner | Provider=MSOLEDBSQL;Data Source=SQLSRV01;Failover Partner=SQLSRV02;Initial Catalog=PlantData;Integrated Security=SSPI;MultiSubnetFailover=True; |
Add MultiSubnetFailover=True for Always On availability groups |
6.3 Stored Procedure vs Ad-Hoc Query
Prefer stored procedures over inline SELECT statements. The reasons are operational, not stylistic:
- Stored procedures give the SQL Server DBA a single place to audit access paths to plant data.
- They survive schema renames when the procedure signature stays stable.
- They are easier to lock down with
GRANT EXECUTEthan table-levelGRANT SELECT.
Calling a stored procedure with one input and one result set:
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandType = 4 ' adCmdStoredProc
cmd.CommandText = "dbo.usp_GetBatchLog"
cmd.Parameters.Append cmd.CreateParameter("@TopN", 3, 1, 0, 50) ' adInteger, adParamInput
Set rs = cmd.Execute
7. Building the Table View That Is Bound to SQL Data
Walk-through for a working screen on WinCC Professional 15.1 with TIA Portal V15.1 Update 6 or later.
7.1 Prerequisites
- TIA Portal V15.1 installed with the WinCC Professional option.
- Microsoft OLE DB Driver for SQL Server 18.x installed on the engineering PC and on every runtime PC.
- A SQL Server login with
GRANT EXECUTEon the target stored procedures, orGRANT SELECTon the target tables. - Defined HMI tag arrays sized to the expected row count. As a rule of thumb, do not exceed 200 rows in a single Table View; WinCC's tag subsystem payload scales linearly.
7.2 Step-by-step
- Open the TIA Portal project, switch to the HMI device, and create three internal tags
MyGrid_Column1,MyGrid_Column2,MyGrid_Column3of typeWString[50]. The[50]array bound defines the maximum row count of the grid. - Open the target screen and insert a Table View control from the toolbox ("Controls" → "Table View").
- Resize the table view to span the screen. In the properties dialog, set
RowCountto 50 andColumnCountto 3. - For each column, set
DataSourceto the corresponding tag array. Set the columnHeaderto the human-readable label. - Set the table view's
UpdateRateto 1000 ms (1 s) for a normal polling workload. Lower this to 500 ms only if the underlying query completes in < 200 ms. - On the screen's
Openevent, callPollSQLGrid(the VBScript in section 3.3). - Add a button "Refresh" whose click event calls
PollSQLGrid. - Compile the project and download to the runtime PC.
- Open WinCC Runtime and verify the table populates within one update cycle.
7.3 Verification checklist
| Check | Method | Pass criterion |
|---|---|---|
| ADODB connection opens | WinCC Runtime diagnostic output (HMI trace) | No -2147467259 (0x80004005) provider error; State reaches adStateOpen
|
| Recordset returns rows | Trace rs.RecordCount after rs.Open
|
RecordCount > 0 within 500 ms |
| Tag arrays written | Online → HMI tags → watch MyGrid_Column1[0..49]
|
Each array element shows a value within 1 update cycle |
| Table View renders rows | Visual inspection | Header and rows match the SQL result |
| No tag overflow | Watch runtime tag diagnostics | No "tag overflow" warnings in the WinCC alarm log |
8. Polling, Performance, and Tag Limits
The Table View is a polling consumer. The runtime reads each cell's DataSource at UpdateRate, and the cumulative poll cost grows with column count × row count. Practical limits observed in V15.1 deployments:
| Configuration | Cell count (cols × rows) | Recommended update rate | Notes |
|---|---|---|---|
| 1 screen, 3 cols × 50 rows | 150 | 500 ms | Typical recipe or batch log view |
| 1 screen, 5 cols × 100 rows | 500 | 1000 ms | Larger alarm log or shift report view; verify with ApDiag.exe on the runtime |
| 1 screen, 10 cols × 200 rows | 2000 | 2000 ms+ | Approaches the comfortable ceiling; consider a server-side stored procedure that pre-aggregates |
| Multiple screens, 5+ overlapping grids | 5000+ | 2000 ms+ | Audit the HMI tag count against the WinCC Professional license; staggered updates with Randomize help avoid synchronized CPU spikes |
8.1 Staggered poll to avoid synchronized CPU load
' On screen-open, schedule the poll on a randomized offset
Randomize
HMIRuntime.Trace "Poll starting in " & Int(Rnd() * 1000) & " ms"
HMIRuntime.SetTimeout Int(Rnd() * 1000), "PollSQLGrid"
9. Version Compatibility Notes (V15.1 → V20)
| TIA Portal version | WinCC Professional build | Table View changes | OLE DB stack |
|---|---|---|---|
| V15.1 | 15.1.0.x | Baseline Table View; VBScript ADODB available | SQLNCLI11 default; MSOLEDBSQL supported if installed |
| V16 | 16.0.x | Table View gains "Filter" column property; runtime supports per-cell text formatting | MSOLEDBSQL 18.x recommended; SQLNCLI11 still present |
| V17 | 17.0.x | Table View gains CSV export; legacy ActiveX list tightened (MSFlexGrid removed from allowed list) | MSOLEDBSQL 18.x; SQLNCLI11 deprecated in installer |
| V18 | 18.0.x | Table View gains light/dark theming; OPC UA column source support | MSOLEDBSQL 19.x; SQLNCLI11 removed from installer |
| V19 | 19.0.x | Table View gains column freeze; performance improvements on 100+ row views | MSOLEDBSQL 19.x |
| V20 | 20.0.x | Table View documented as the canonical tabular control for RT Professional; Table view (RT Professional) | MSOLEDBSQL 19.x; Microsoft.Data.SqlClient not used in VBScript |
10. Troubleshooting Matrix
| Symptom | Error code | Likely root cause | Remediation |
|---|---|---|---|
| Connection.Open throws |
-2147467259 (0x80004005) "Unspecified error" |
Provider not installed on the runtime PC, or wrong bitness | Install MsOleDBDriverForSqlServer (64-bit) on the runtime PC; check appwiz.cpl
|
| Connection.Open throws |
-2147217865 (0x80040E37) "Invalid object name" |
Login authenticated but schema/table not found in default DB | Set Initial Catalog in the connection string; verify default schema for the login |
| Connection.Open throws |
-2147217843 (0x80040E4D) "Login failed for user" |
Wrong credentials or account locked | Verify the WinCC Runtime service account; for SQL auth, check Password Policy in SQL Server |
| rs.Open hangs or times out | n/a | Long-running query, missing index, or blocked session | Run the same SQL in SSMS with SET STATISTICS TIME ON; add indexes or pre-aggregate |
| Table View shows blank rows but no errors | n/a | Array tag not bound to the column, or array length is 0 | Verify each column's DataSource in the Table View properties; verify tag array length in HMI tags |
| Table View shows stale rows | n/a | Polling script not running on screen open | Check the screen's Open event in the TIA Portal; verify VBScript syntax compiles |
| Table View cells flicker or display "#####" | n/a | Column width too small for the value, or value type mismatch | Increase column width; ensure String columns use WString tag type |
| MSFlexGrid / VB6 DataGrid uneditable after TIA restart | n/a | ActiveX registered for editor, not runtime; OCX state reset | Replace with Table View or PM-GRID; do not deploy VB6 OCX to a 64-bit WinCC Runtime |
| VBScript compile error: "Variable is undefined: ADODB" | n/a | Script type set to "VB" instead of "VBScript" | In the script properties dialog, set language to VBScript
|
| Table View does not show archived values | n/a | Logged column source requires a configured tag logging database | Open WinCC Explorer → "Tag Logging" → verify a database is configured and the time range is correct |
| Runtime crashes when grid populates | varies | Null values in the SQL result set, or empty strings passed to a Real array | Wrap the assignment in If IsNull(rs(...)) Then ... Else ...; never assign a null to a numeric tag |
11. Field-Proven Patterns
11.1 Guarding against null in numeric columns
Function SafeReal(v)
If IsNull(v) Then
SafeReal = 0
ElseIf IsEmpty(v) Then
SafeReal = 0
ElseIf VarType(v) = vbString And Len(v) = 0 Then
SafeReal = 0
Else
SafeReal = CDbl(v)
End If
End Function
11.2 Closing the connection even on error
On Error Resume Next
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
If Err.Number <> 0 Then
HMIRuntime.Trace "Cleanup error: " & Err.Number & " " & Err.Description
Err.Clear
End If
On Error Goto 0
11.3 Using a tag logging database as the buffer
For data that updates more frequently than 1 s, write the SQL result into a configured tag logging database (WinCC "Tag Logging" → "Process Tag" configuration) and bind the Table View to the logged source. This decouples the SQL poll from the screen update rate and lets the table view consume batched data via WinCC's read-optimized path. The write-side VBScript uses the WinCC logging API:
' Write a single row to a configured logging tag
Dim logTag
Set logTag = HMIRuntime.Logging("MyLoggingTag")
logTag.LogValue CLng(Now), SafeReal(rs("Temperature").Value), 0 ' quality = good
12. Summary and Decision Path
For a project on WinCC Professional 15.1 that needs to show SQL Server data in a grid, the decision is short:
- If the grid shows already-logged data or a static snapshot, use the Table View (RT Professional). It is free, documented, and supported. Mirror the SQL data into HMI tag arrays on a 500–2000 ms poll. See the Table view (RT Professional) reference for the current property set.
- If the grid needs free-form SQL Server data, user-editable cells, or complex cell types, license the PM-GRID Control from PM Options. It is the only grid control Siemens has built for the WinCC Runtime host.
- Do not use MSFlexGrid, MSHFlexGrid, or VB6 DataGrid. They are not supported in a 64-bit WinCC Runtime and will not survive a TIA Portal restart.
Does WinCC Professional 15.1 ship a DataGrid control?
No. The screen toolbox exposes HMI controls only; there is no System.Windows.Forms.DataGrid or WPF DataGrid in the runtime. Use the Table View (RT Professional) for static or logged tabular data, or the licensed PM-GRID Control for free-form SQL Server grids.
Why does MSFlexGrid become uneditable after a TIA Portal restart?
The OCX is registered for the editor process but not the WinCC Runtime process. On restart the runtime loads the control in a hardened context, the persisted OCX state is reset, and the control reverts to an uneditable blank. On 64-bit runtime PCs the underlying VB6 OCX is also 32-bit and will not load at all.
Which OLE DB provider should I use for SQL Server on WinCC Professional 15.1?
Use MSOLEDBSQL (Microsoft OLE DB Driver for SQL Server, version 18.x or newer). Install it on the engineering PC and on every runtime PC. The legacy SQLNCLI11 is supported but deprecated; SQLOLEDB is removed from the V17+ installer.
Can VBScript open an ADODB Recordset in WinCC Professional 15.1?
Yes. CreateObject("ADODB.Connection") and CreateObject("ADODB.Recordset") work in VBScript routines, but the recordset cannot be assigned directly to a Table View's DataSource. You must copy the rows into HMI tag arrays and bind each column to an array element.
How do I display more than 200 rows in a Table View?
Either raise the array tag length and the table view's row count and accept the 2000 ms+ update rate, or store the SQL result in a configured tag logging database and bind the Table View to the logged source for a batched read path. The logged source path scales to thousands of rows at 1 s update rate.
What is the difference between Table View and PM-GRID Control?
Table View is included with WinCC Professional, binds to HMI tag arrays, and is configured at design time. PM-GRID is a separately licensed add-on from the PM Options team that binds to an ADODB Recordset, supports user-editable cells, and exposes master/detail, grouping, and rich cell types.