Overview
SIMATIC WinCC V7.0 SP3 offers two production-ready paths for exchanging process data with Microsoft SQL Server:
- The licensed User Archive option, which creates, manages, and persists structured tables inside the WinCC runtime database and exposes them to graphics runtime through the
UserArchiveTableActiveX control. - Direct VBScript access through ADO (ActiveX Data Objects) with the
SQLOLEDBorSQLNCLIprovider, which can connect to any local or remote SQL Server instance and read or write from a WinCC Global Action, a button event, or a scheduled C-script action.
User Archive is the right answer when the dataset lifetime equals the project lifetime and no external BI tool needs to query the data directly. Direct ADO is the right answer when you must share data with MES, SAP, an existing SCADA historian, or any third-party application that already owns the table schema. This article covers both paths, supplies working VBScript examples for connect / read / write, and documents the SQL Server authentication vulnerability published by CISA as ICSA-12-205-01 that affects WinCC V7.0 SP3 and earlier.
Prerequisites
| Item | Requirement |
|---|---|
| WinCC version | SIMATIC WinCC V7.0 SP3 (build 13.0.x) on engineering and runtime station |
| SQL Server | Microsoft SQL Server 2005, 2008, or 2008 R2 (Express or Standard) |
| Provider | SQL Server Native Client 10.0 (SQLNCLI10) or Microsoft OLE DB Provider for SQL Server (SQLOLEDB) |
| User Archive | WinCC User Archive option licensed (separate license key on runtime) |
| WinCC tags | Internal or process tags defined for the values to be stored / retrieved |
| Permissions | SQL login with db_datareader / db_datawriter on the target database |
| Firewall | TCP 1433 (default instance) or dynamic port for named instance open between WinCC and SQL |
SQLNCLI10 provider string for stable behaviour.Architecture: WinCC RT Database vs. External SQL
WinCC V7.0 SP3 stores its own runtime state in a Microsoft SQL Server instance installed as part of the WinCC setup (default instance name WINCC). All process tags, alarms, and tag logging rows are persisted in this embedded instance. The User Archive option simply adds additional tables to the same instance under the database CC_UserArchive_<ProjectName>_<ServerPrefix>.
An external SQL Server (typically used by MES, ERP, or a corporate historian) is a separate instance. The connection topology is:
Method 1 - WinCC User Archive (Built-in)
The User Archive editor in WinCC Explorer defines the schema, indexes, and primary key of the table. The runtime populates the rows; the UserArchiveTable ActiveX displays them in a grid that is fully configurable at runtime (column width, filter, sort, multi-select). Refer to the WinCC Information System section Options > User Archive in the WinCC V7.0 SP3 help and the Siemens KB article 10095491 for the full reference.
Step-by-step: Create a User Archive
- Open WinCC Explorer, right-click User Archive, choose New Archive.
- Define columns:
ID(Integer, primary key, auto-increment),Timestamp(Date/Time),TagName(String, 50),TagValue(Float, double precision),Quality(String, 8). - Enable Allow only one client for writing for safety when multiple WinCC clients can write.
- Set Update cycle for read-only archives that should be reloaded on a timer.
- Compile and activate the project. The table is created automatically on first start in
CC_UserArchive_<ProjectName>_<Prefix>.
Step-by-step: Display the User Archive in a picture
- Open the Graphics Designer. From the Smart Objects palette insert UserArchiveTable control.
- In the control properties, link the field Source to the configured archive name.
- Configure column properties: visibility, width, alignment, format string.
- Use the
uaAppend,uaDelete,uaRead,uaWriteVBScript methods on theHMIRuntimeobject to populate rows from process tags. See the VBScript methods reference in the WinCC V7.0 SP3 help under Programming VBS > User Archive.
VBScript example - Write process tag value to User Archive
Dim ua, op
Set ua = HMIRuntime.UserArchives("ProductionData")
op = ua.uaAppend
If op = 0 Then
Dim row
Set row = HMIRuntime.UserArchives("ProductionData").uaGetFieldCollection
row.Item("TagName").Value = "Motor_Speed"
row.Item("TagValue").Value = HMIRuntime.Tags("Motor_Speed").Read
row.Item("Timestamp").Value = Now
row.Item("Quality").Value = HMIRuntime.Tags("Motor_Speed").Quality
HMIRuntime.UserArchives("ProductionData").uaSetFieldCollection row
End If
uaAppend. Zero is success; non-zero values are archive-specific error codes returned by the runtime.Method 2 - Direct ADO / OLE DB from VBScript
Use the ADO model when the target table lives in a SQL Server instance outside the WinCC project database, or when a third-party tool owns the schema and you only have INSERT and SELECT rights.
Connection String Reference
| Provider | Connection String | Notes |
|---|---|---|
| SQLOLEDB (legacy) | Provider=SQLOLEDB;Data Source=SRV\INST;Initial Catalog=DB;User ID=u;Password=p; |
Built into Windows, deprecated |
| SQLNCLI10 | Provider=SQLNCLI10;Server=SRV\INST;Database=DB;Uid=u;Pwd=p; |
Recommended for WinCC V7.0 SP3 |
| SQLNCLI11 | Provider=SQLNCLI11;Server=SRV\INST;Database=DB;Uid=u;Pwd=p; |
Requires Native Client 2012 |
| ODBC via MSDASQL | Provider=MSDASQL;DRIVER={SQL Server};SERVER=SRV;DATABASE=DB;UID=u;PWD=p; |
Use only if OLE DB providers are blocked |
| Trusted connection | Provider=SQLNCLI10;Server=SRV;Database=DB;Integrated Security=SSPI; |
Requires matching Windows account on both hosts |
Helper procedure - Open connection
Function OpenSqlConn(serverName, dbName, userName, password)
Dim conn, cs
Set conn = CreateObject("ADODB.Connection")
cs = "Provider=SQLNCLI10;Server=" & serverName & ";Database=" & dbName & ";Uid=" & userName & ";Pwd=" & password & ";"
conn.ConnectionTimeout = 10
conn.CommandTimeout = 30
conn.Open cs
Set OpenSqlConn = conn
End Function
Step-by-step: Write a WinCC tag to an external SQL table
- In Graphics Designer place a button. Configure the event Mouse > Left Click as a VBScript action.
- Create the destination table in the external SQL instance:
CREATE TABLE ProductionData ( ID INT IDENTITY(1,1) PRIMARY KEY, TagName NVARCHAR(50) NOT NULL, TagValue FLOAT NULL, Quality NVARCHAR(8) NULL, StampUtc DATETIME NOT NULL DEFAULT (GETUTCDATE()) ) - Click event script:
Sub OnClick(ByVal Item) Dim conn, cmd, val Set conn = OpenSqlConn("MYSERVER\SQLEXPRESS", "MesData", "WinCCUser", "P@ssw0rd!") Set cmd = CreateObject("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandText = "INSERT INTO ProductionData (TagName, TagValue, Quality) VALUES (?,?,?)" cmd.CommandType = 1 ' adCmdText cmd.Parameters.Append cmd.CreateParameter("p1", 200, 1, 50, "Motor_Speed") val = HMIRuntime.Tags("Motor_Speed").Read cmd.Parameters.Append cmd.CreateParameter("p2", 5, 1, 8, val) cmd.Parameters.Append cmd.CreateParameter("p3", 200, 1, 8, HMIRuntime.Tags("Motor_Speed").Quality) cmd.Execute , , 128 ' adExecuteNoRecords conn.Close Set cmd = Nothing Set conn = Nothing End Sub - Use a Global Action to write the tag value to SQL on every change. Configure a Standard cycle of 1 s and compare against the previous value to avoid flooding the table.
Step-by-step: Read from external SQL into a WinCC tag
- Create the destination WinCC internal tag
DB_Motor_Speedof type Signed 32-bit or Float. - On a button click or scheduled Global Action, run:
Sub OnRead(ByVal Item) Dim conn, rs Set conn = OpenSqlConn("MYSERVER\SQLEXPRESS", "MesData", "WinCCUser", "P@ssw0rd!") Set rs = CreateObject("ADODB.Recordset") rs.CursorType = 3 ' adOpenStatic rs.LockType = 3 ' adLockOptimistic rs.Open "SELECT TOP 1 TagValue FROM ProductionData WHERE TagName='Motor_Speed' ORDER BY StampUtc DESC", conn If rs.EOF Then HMIRuntime.Trace "No row for Motor_Speed" & vbCrLf ElseIf IsNull(rs.Fields("TagValue").Value) Then HMIRuntime.Trace "NULL value" & vbCrLf Else HMIRuntime.Tags("DB_Motor_Speed").Write rs.Fields("TagValue").Value End If rs.Close conn.Close Set rs = Nothing Set conn = Nothing End Sub - Verify in WinCC Explorer with Tag Simulation or in Graphics Runtime by adding an I/O field bound to
DB_Motor_Speed.
Displaying Query Results in a WinCC Table Control
To display arbitrary result sets (not just User Archives) inside a WinCC picture, push the rows into a MSFlexGrid or MSHFlexGrid control, or use the DataGrid ActiveX with a bound ADODB recordset. The simplest path is the legacy MSFlexGrid COM control, which WinCC still ships and supports in V7.0 SP3.
Sub FillGrid()
Dim conn, rs, g, i
Set conn = OpenSqlConn("MYSERVER\SQLEXPRESS", "MesData", "WinCCUser", "P@ssw0rd!")
Set rs = conn.Execute("SELECT StampUtc, TagName, TagValue FROM ProductionData ORDER BY StampUtc DESC")
Set g = ScreenItems("GridResults")
g.Rows = rs.RecordCount + 1
g.Cols = rs.Fields.Count
g.TextMatrix(0,0) = "Time" : g.TextMatrix(0,1) = "Tag" : g.TextMatrix(0,2) = "Value"
i = 1
Do While Not rs.EOF
g.TextMatrix(i,0) = rs.Fields(0).Value
g.TextMatrix(i,1) = rs.Fields(1).Value
g.TextMatrix(i,2) = rs.Fields(2).Value
rs.MoveNext
i = i + 1
Loop
rs.Close : conn.Close
Set rs = Nothing : Set conn = Nothing
End Sub
Error Handling and Diagnostics
Every ADODB call in VBScript can raise a runtime error. Wrap database code with On Error Resume Next and read Err.Number / Err.Description for diagnostics. Common ADO error codes:
| Err.Number | Meaning | Typical cause |
|---|---|---|
| -2147467259 (0x80004005) | General provider failure | Wrong server name, SQL service stopped, named pipes disabled |
| -2147217865 (0x80040E37) | Table not found | Schema not deployed, wrong Initial Catalog |
| -2147217900 (0x80040E14) | Syntax error | Reserved word used as column name without brackets |
| -2147217864 (0x80040E38) | Lock timeout / deadlock | Row locked by another transaction |
| -2147217911 (0x80040E09) | Login failed | Wrong password, account disabled, SQL auth mode off |
For deeper diagnostics set the provider's SQL Server Profiler trace and run a VBScript test using cscript.exe on the WinCC station. Use the WinCC APDiag and DiagMonitor tools to confirm that the runtime process is reaching the VBScript at all.
Security: CISA ICSA-12-205-01
In July 2012, CISA (then ICS-CERT) published ICSA-12-205-01, a vulnerability advisory covering an insecure default SQL Server authentication configuration shipped with SIMATIC WinCC V7.0 SP3 and earlier. The advisory states that the WinCC installer configures the bundled SQL Server with a well-known administrative account whose credentials are documented and reachable from the network, allowing an unauthenticated remote attacker to gain full read/write access to the WinCC runtime database, modify process values, and disrupt operations.
Performance Considerations
- Use parameterised commands (
cmd.Parameters.Append ...) instead of string concatenation. Parameterised commands are precompiled by the server and are immune to SQL injection. - Throttle writes to one row per 250 ms or slower. WinCC Global Actions run in the same thread as the picture update, so excessive database traffic will stall the runtime UI.
- Use a connection pool by keeping a single ADODB.Connection object as a module-level reference; do not open and close a connection on every event.
- For high-volume logging (thousands of rows per second) use the WinCC Tag Logging fast option and configure the database swap path rather than ADO inserts.
- Index the columns you filter on. For a typical
TagName + Timestampquery a composite indexCREATE INDEX IX_PD_Tag_Time ON ProductionData(TagName, StampUtc DESC)will keep the read latency under 10 ms even on a multi-million-row table.
Troubleshooting Matrix
| Symptom | Probable Cause | Fix |
|---|---|---|
| VBScript never fires | Action not compiled, picture not activated | Activate picture, check Project Properties > Options > Run VBS Actions |
| Provider not found error | SQLNCLI10 not installed | Install SQL Server 2008 Native Client on the runtime station |
| Login failed for user 'sa' | Mixed-mode auth disabled, weak password policy | Enable mixed mode in SQL Server Management Studio, set a strong password |
| Write succeeds but value is 0 | Tag type mismatch, wrong conversion | Cast with CStr / CDbl and verify with a test query |
| Recordset stays open after error | Missing cleanup in error path | Use On Error GoTo 0 after handling and close objects |
| User Archive table empty in runtime | Archive not linked to a source connection | Verify column Source in the UserArchiveTable control |
| High CPU on WinCC runtime | Global Action with 100 ms cycle calling ADO | Throttle to 1 s or trigger on tag change only |
Verification Checklist
- In WinCC Explorer, open Tools > Cross Reference and confirm the VBScript action is referenced from the picture.
- Start Graphics Runtime, click the write button, then run
SELECT TOP 10 * FROM ProductionData ORDER BY StampUtc DESCin SQL Management Studio. - Modify the value in SQL directly with an UPDATE, click the read button, and verify the I/O field updates.
- Watch the APDiag output for any VBScript exception with
On Error Resume Nexttraces. - Confirm firewall rules:
Test-NetConnection -ComputerName MYSERVER -Port 1433from PowerShell on the runtime station must return TcpTestSucceeded : True. - Confirm the SQL Server login can be reached: from the WinCC station run
sqlcmd -S MYSERVER\SQLEXPRESS -U WinCCUser -P P@ssw0rd! -Q "SELECT 1".
Field-Proven Tips
- Always store timestamps in UTC. The local time on the SQL Server and the WinCC station can drift by hours, and daylight saving changes will break chronological reports.
- Use
HMIRuntime.Tracein the VBScript and tail the WinCC trace file inC:\Program Files\Siemens\Automation\WinCC\Diagnosefor rapid diagnosis in the field. - When a single value must be both written and read, build a small DBManager COM component once and call it from every picture, rather than duplicating ADO code in each event.
- For redundant WinCC servers, configure the User Archive on the master only and let the standby replicate with WinCC Redundancy; do not run direct ADO from both servers to the same external table or you will get duplicate inserts on failover.
Related Siemens Documentation
- Siemens KB 10095491 - User Archive configuration basics
- Siemens KB 11925601 - User Archive scripting samples
- Siemens KB 2463816 - Displaying User Archive data in runtime
- CISA ICS Advisory ICSA-12-205-01 - WinCC SQL Server authentication
What is the difference between User Archive and direct ADO access in WinCC 7.0 SP3?
User Archive stores structured tables inside the WinCC runtime SQL instance and is exposed to graphics runtime through the UserArchiveTable ActiveX; it requires a User Archive license. Direct ADO from VBScript connects to any external SQL Server using SQLOLEDB or SQLNCLI10 and does not require the User Archive license, but you must write the read/write VBScript yourself.
Which SQL Server provider should I use with WinCC V7.0 SP3 on Windows Server 2008 R2?
Use Provider=SQLNCLI10 (SQL Server 2008 Native Client). Install the SQL Server 2008 Feature Pack on the WinCC runtime station and reference the provider as SQLNCLI10 in your VBScript connection string.
How do I display an external SQL query result in a WinCC table?
Place an MSFlexGrid control on the picture, bind it to a tag, and populate TextMatrix(row, col) from the ADODB.Recordset inside a VBScript action. For a more native look, use the WinCC User Archive approach and load the table once with the same SELECT statement.
Why does my VBScript action return error -2147467259 (0x80004005) when opening the connection?
This is the generic provider error. Most often it is caused by an incorrect server name, the SQL Server service being stopped, or a firewall blocking TCP 1433. Verify with Test-NetConnection from PowerShell, check that the SQL Server Browser service is running for named instances, and confirm that the SQL Server protocol TCP/IP is enabled in SQL Server Configuration Manager.
Is WinCC 7.0 SP3 affected by the CISA ICS vulnerability ICS-12-205-01?
Yes. ICS-12-205-01 documents an insecure default SQL Server authentication configuration in WinCC V7.0 SP3 and earlier. Apply the Siemens update referenced in the advisory, change the default SQL password, restrict the SQL port with the Windows Firewall, and isolate the WinCC station on a control LAN. Full details are at CISA ICS-12-205-01.