1. Overview
Siemens WinCC supports direct database access from runtime scripts using VBScript, allowing HMIs and SCADA stations to read/write process values, alarms, audit trails, and production data to a Microsoft SQL Server backend. The connection path is always the same at the operating-system level: WinCC VBScript creates an ADODB.Connection object, which talks to an OLE DB provider, which in turn loads an ODBC driver that finally talks to SQL Server. The single most frequent failure point is the provider string itself: the wrong provider, a missing data source name (DSN), or a 32-bit/64-bit driver mismatch returns ADODB.Connection.Open error 0x800A0E7A or 0x80004005.
This reference consolidates the configuration steps documented in Siemens Entry IDs 61883659 and 61886098, adds the OLE DB/ODBC provider matrix required by current Windows and SQL Server versions, and supplies verified VBScript examples and a troubleshooting matrix for field engineers.
2. Product Family Disambiguation
| Attribute | WinCC V7 / V7.2 / V7.4 / V7.5 | WinCC Advanced (TIA Portal) |
|---|---|---|
| Engineering environment | SIMATIC Manager / WinCC Explorer | TIA Portal (V13–V18) |
| Scripting language | VBScript (WinCC scripts) and ANSI-C | VBScript (WinCC Advanced scripts) |
| Database backend | Microsoft SQL Server 2005/2008 R2/2012/2014/2016/2019 (embedded or external) | None internal; SQL connectivity provided via ODBC/OLE DB from VBS |
| ODBC Administrator | Both 32-bit and 64-bit present; runtime is 32-bit on WinCC V7 stations | 32-bit only on TIA Portal HMI panels/PC Runtime |
| Primary Siemens FAQ Entry ID | 61883659 (VBS & SQL) | Same entry applies to Advanced |
| Microsoft SQL setup FAQ | 61886098 | |
If your project was created in TIA Portal, the documented behaviour of chapter 2.1 of Entry 61883659 applies directly. If you are running WinCC V7.x (classic), the same OLE DB provider strings are valid but the SQL Server Express instance installed by WinCC Setup is pre-bound to the WinCC project.
3. Prerequisites
- SQL Server instance reachable from the HMI/PC station. Microsoft SQL Server 2014, 2016, 2017, 2019, or 2022 in any edition. SQL Server Express (free) is acceptable for non-redundant WinCC stations.
-
TCP port 1433 open between the runtime PC and the SQL host. Verify with
Test-NetConnection -ComputerName <sqlhost> -Port 1433on PowerShell ortelnet sqlhost 1433. - Authentication method decided. Either SQL Server Authentication (login/password) or Windows Authentication (requires identical or trusted AD accounts on both hosts).
- Matching ODBC driver installed. 32-bit drivers for 32-bit WinCC runtime, 64-bit for 64-bit. Modern SQL Server installations should use ODBC Driver 17 for SQL Server or ODBC Driver 18 for SQL Server.
- Administrative rights on the runtime PC to register the DSN via ODBC Data Source Administrator (32-bit / 64-bit).
- WinCC runtime running as a user with rights to read the DSN. Either run WinCC Runtime as a service account that owns the DSN, or create a System DSN visible to all users.
4. ODBC and OLE DB Provider Architecture
VBScript in WinCC is hosted by the Windows Script Host and can only consume OLE DB providers via the ADODB type library. ODBC drivers are reached through the Microsoft OLE DB-to-ODBC bridge provider (MSDASQL) or, preferably, through a native OLE DB provider such as SQLNCLI / MSOLEDBSQL. The chain is:
- WinCC VBScript creates
ADODB.Connection. -
Connection.Provider = "…"selects the OLE DB provider. - Provider loads the ODBC driver identified by the DSN or the connection string.
- Driver opens a TCP/TDS session to SQL Server.
4.1 Provider String Reference
| Provider | ProgID / CLSID | Connection string token | Use case |
|---|---|---|---|
| Microsoft OLE DB Driver 18 for SQL Server | MSOLEDBSQL | Provider=MSOLEDBSQL;… |
Recommended for SQL Server 2017+ |
| Microsoft OLE DB Driver 19 for SQL Server | MSOLEDBSQL19 | Provider=MSOLEDBSQL19;… |
Recommended for SQL Server 2022 |
| SQL Server Native Client 11.0 (SQLNCLI11) | SQLNCLI11 | Provider=SQLNCLI11;… |
SQL Server 2012/2014, deprecated but widely deployed |
| SQL Server Native Client 10.0 (SQLNCLI10) | SQLNCLI10 | Provider=SQLNCLI10;… |
SQL Server 2008 R2 |
| Microsoft OLE DB Provider for ODBC (bridge) | MSDASQL | Provider=MSDASQL;DSN=MyDSN;… |
Generic fallback, requires ODBC DSN |
| .NET Framework Data Provider for OLE DB | (not directly usable from VBS) | n/a | n/a in WinCC VBS context |
SQLOLEDB provider shipped with Windows MDAC is removed from Windows 11 22H2 and later. Never ship a new project with Provider=SQLOLEDB. Use MSOLEDBSQL or MSOLEDBSQL19 instead. See Microsoft OLE DB Driver for SQL Server documentation.4.2 ODBC Driver Reference
| Driver name (as displayed in ODBC Administrator) | Driver file | Recommended for |
|---|---|---|
| ODBC Driver 18 for SQL Server | msodbcsql18.dll | SQL Server 2017–2022 |
| ODBC Driver 17 for SQL Server | msodbcsql17.dll | SQL Server 2012–2019 |
| ODBC Driver 13.1 for SQL Server | msodbcsql13.dll | SQL Server 2008–2016 |
| SQL Server Native Client 11.0 | sqlncli11.dll | Legacy SQL 2012/2014 |
| SQL Server | sqlsrv32.dll (legacy) | Deprecated, MDAC only |
5. Step-by-Step: Creating the ODBC Data Source
The data source name (DSN) is the lookup key the VBScript Provider resolves at runtime. The DSN stores the driver name, server address, authentication, and default database.
5.1 Open the Correct ODBC Administrator
Windows ships two ODBC administrators. WinCC runtime is a 32-bit process on every currently supported release (V7 and TIA Portal Advanced/Professional), so the 32-bit ODBC administrator is the one that matters:
- Press
Win + R, type%windir%\SysWOW64\odbcad32.exe, press Enter. This is the 32-bit administrator on 64-bit Windows. - The 64-bit version is at
%windir%\System32\odbcad32.exe. Configuring a 64-bit DSN for a 32-bit WinCC runtime is a common cause of "Data source name not found and no default driver specified" errorIM002.
5.2 Add a System DSN
- Select the System DSN tab and click Add….
- Pick the driver ODBC Driver 18 for SQL Server (or 17 / 11.0 matching your SQL Server version).
- In the wizard:
-
Name:
WinCC_SQL(must match the VBScript connection string exactly, case-insensitive on Windows). -
Description:
WinCC runtime data source. -
Server:
SERVERNAME\INSTANCENAMEorSERVERNAME,1433for non-default ports.
-
Name:
- Choose authentication: With SQL Server authentication… for username/password, or With Integrated Windows authentication… for Kerberos/NTLM.
- Tick Change the default database to: and select your target database.
- Leave default options. For driver 18+ tick Encrypt=Yes and choose the certificate trust option appropriate to your environment (in lab: Optional; in production: Mandatory with a real CA cert).
- Test the data source with the Test Data Source… button. A successful test shows SQLSTATE 01000 / Microsoft SQL Server login succeeded.
5.3 Configuring SQL Server to Accept the Connection
If the test fails with SQL Server does not exist or access denied:
- Open SQL Server Configuration Manager on the SQL host.
- Expand SQL Server Network Configuration > Protocols for <INSTANCE> and enable TCP/IP.
- Right-click TCP/IP > Properties > IP Addresses tab; verify the listening port (default 1433) under IPAll.
- Restart the SQL Server service.
- Confirm the Windows Firewall rule SQL Server (TCP-in) is enabled for the SQL Server service binary path.
- Create a SQL login if using SQL auth:
CREATE LOGIN [WinCCUser] WITH PASSWORD = 'StrongP@ssw0rd!';then map it to a database user in your target DB.
6. WinCC VBScript: Connection Strings and Provider Names
Chapter 2.1 of Siemens FAQ 61883659 requires exactly two parameters to open a data source: the Provider and the Data Source (DSN). Additional connection string parameters are passed as required.
6.1 Connection Using Native OLE DB Provider (Recommended)
' WinCC VBScript - connect via OLE DB Driver 18 for SQL Server
Dim conn, cmd, rs, connStr
Set conn = CreateObject("ADODB.Connection")
connStr = "Provider=MSOLEDBSQL;" & _
"Server=SQLHOST\SQLEXPRESS,1433;" & _
"Database=ProductionData;" & _
"UID=WinCCUser;" & _
"PWD=StrongP@ssw0rd!;" & _
"Encrypt=Yes;" & _
"TrustServerCertificate=No;" & _
"Application Name=WinCC_RT;"
conn.ConnectionTimeout = 10
conn.CommandTimeout = 30
On Error Resume Next
conn.Open connStr
If Err.Number <> 0 Then
HMIRuntime.Trace "ADODB.Open failed: " & Err.Number & " / " & Err.Description & vbNewLine
Err.Clear
End If
On Error Goto 0
6.2 Connection Using ODBC DSN with MSDASQL Bridge
' WinCC VBScript - connect through the ODBC bridge using a DSN
Dim conn, rs
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = _
"Provider=MSDASQL;" & _
"DSN=WinCC_SQL;" & _
"UID=WinCCUser;" & _
"PWD=StrongP@ssw0rd!;"
conn.ConnectionTimeout = 10
conn.Open
6.3 Connection Using DSN-Less Native Client
' DSN-less connection with SQL Server Native Client 11.0 (legacy)
Dim conn
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = _
"Provider=SQLNCLI11;" & _
"Server=SQLHOST\SQLEXPRESS;" & _
"Database=ProductionData;" & _
"Integrated Security=SSPI;" & _
"DataTypeCompatibility=80;" & _
"MARS Connection=True;"
conn.Open
6.4 Parameter Reference
| Parameter | Meaning | Example |
|---|---|---|
Provider |
OLE DB provider ProgID | MSOLEDBSQL |
Server |
Hostname\Instance or IP,port | SQL01\WINCC,1433 |
Database |
Default catalog after login | WinCC_DB |
UID / PWD
|
SQL auth credentials | UID=sa;PWD=… |
Integrated Security=SSPI |
Use Windows auth | No UID/PWD |
Encrypt=Yes |
Force TLS (driver 18+) | Encrypt=Yes;TrustServerCertificate=No; |
Application Name |
Shown in SQL sys.dm_exec_sessions
|
Application Name=WinCC_HMI_07 |
DataTypeCompatibility=80 |
SQL 2000-compatible types | Use only with SQLNCLI10/11 |
MARS Connection=True |
Multiple Active Result Sets | Required by some WinCC scripts |
7. Reading and Writing Process Data
' Insert a batch record into ProductionData.dbo.Batches
Dim conn, cmd, batchID
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = "Provider=MSOLEDBSQL;Server=SQL01;Database=ProductionData;" & _
"UID=WinCCUser;PWD=StrongP@ssw0rd!;Encrypt=Yes;"
conn.Open
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO dbo.Batches (BatchNo, StartTime, Operator) VALUES (?, ?, ?)"
cmd.Parameters.Append cmd.CreateParameter("BatchNo", 200, 1, 32, "B2024-0007") ' adVarChar, adParamInput
cmd.Parameters.Append cmd.CreateParameter("StartTime", 135, 1, , Now) ' adDBTimeStamp
cmd.Parameters.Append cmd.CreateParameter("Operator", 200, 1, 32, HMIRuntime.Tags("@UserName").Read)
cmd.Execute , , 128 ' adExecuteNoRecords
batchID = conn.Execute("SELECT SCOPE_IDENTITY()")(0)
HMIRuntime.Trace "Inserted BatchID=" & batchID & vbNewLine
conn.Close
Set cmd = Nothing
Set conn = Nothing
' Read the latest 50 alarms from SQL into WinCC internal tags
Dim conn, rs, i
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = "Provider=MSOLEDBSQL;Server=SQL01;Database=ProductionData;" & _
"UID=WinCCUser;PWD=StrongP@ssw0rd!;Encrypt=Yes;"
conn.Open
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 ' adUseClient
rs.Open "SELECT TOP 50 AlarmTime, Tag, Priority, Message FROM dbo.AlarmLog ORDER BY AlarmTime DESC", conn
i = 0
Do While Not rs.EOF And i < 50
HMIRuntime.Tags("AlarmText_" & i).Write rs.Fields("Message").Value
i = i + 1
rs.MoveNext
Loop
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
8. Verification Procedure
-
DSN test: Open
odbcad32.exe(32-bit), select WinCC_SQL, click Configure > Test Data Source. Expect Microsoft SQL Server login succeeded within 3 seconds on a LAN. -
VBScript connection test: Run a minimal script (Section 6.1) from the WinCC script editor in runtime. Trace output ADODB.Open failed: … indicates the error code; a clean trace means
Err.Number = 0and the connection succeeded. -
SQL-side verification: From SSMS run
SELECT program_name, login_name, host_name FROM sys.dm_exec_sessions WHERE program_name = 'WinCC_RT';. Each successful WinCC connection should appear within 10 s. -
Performance smoke test: Time a 1 000-row
SELECTusingTimerin VBS. Healthy LAN: < 200 ms; > 1 s indicates network latency, missing indexes, or wrong provider. - Process-data round trip: Insert a row from WinCC, read it back via SSMS, then update from SSMS and read back from WinCC. Confirms bidirectional access.
9. Troubleshooting Matrix
| Symptom / Err.Number | Hex | Likely root cause | Fix |
|---|---|---|---|
| Data source name not found and no default driver specified (IM002) | 0x80004005 | DSN created in 64-bit ODBC admin but runtime is 32-bit (or vice versa) | Open %windir%\SysWOW64\odbcad32.exe and recreate the System DSN there |
| Provider cannot be found. It may not be properly installed | 0x800A0E7A | Provider string typo, or driver not installed | Install OLE DB Driver 18 for SQL Server; verify spelling of MSOLEDBSQL
|
| [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied | 0x80004005 | Wrong server name, SQL service down, firewall blocking 1433 | Test with Test-NetConnection; enable TCP/IP and the firewall rule; verify instance name |
| Login failed for user '…' | 0x80040E4D / 18456 | Bad credentials, mixed Windows/SQL auth, AD trust broken | Reset SQL login, enable SQL Server and Windows Authentication mode, confirm Kerberos SPNs |
| SSL Provider: The certificate chain was issued by an authority that is not trusted | -2147467259 | Driver 18 default Encrypt=Yes + self-signed SQL cert |
Add TrustServerCertificate=Yes for test, or install a proper CA-signed cert for production |
| Cannot create ActiveX component | 0x800A01AD | ADODB not registered (rare on WinCC stations) | Re-register msado15.dll: regsvr32 "C:\Program Files (x86)\Common Files\System\ado\msado15.dll"
|
| Operation is not allowed when the object is closed | 0x800A0E78 | Connection dropped between scripts | Wrap conn.Open in a function and reuse; set ConnectionTimeout = 0 and reconnect on demand |
| Long delays before timeout | n/a | DNS or IPv6 resolution stalling | Use IP address, disable IPv6 on SQL host, or append ;Network Library=DBMSSOCN
|
| Multiple-step OLE DB operation generated errors | 0x80040E21 | Cursor location mismatch, type coercion | Set rs.CursorLocation = 3 (adUseClient); verify column types |
10. Security and Hardening
- Never embed passwords in scripts. Use a WinCC internal tag of type String in a restricted authorization area, or read from an encrypted file using the WinCC @ServerName mapping.
-
Use least-privilege logins. Grant the WinCC user
db_datareaderanddb_datawriteron the production database only; do not usesa. -
Force TLS. Driver 18 defaults to
Encrypt=Yes; pair with a CA-signed SQL Server certificate in production. - Restrict the SQL Server port. Bind SQL to a fixed port and add a Windows Firewall rule allowing only the WinCC subnet.
- Enable auditing. In SSMS > Server Properties > Security > set Login auditing to Failed logins only at minimum.
- Disable SA. Rename the SA account and disable it after creating named logins.
-
Audit WinCC scripts centrally. Log every
conn.Openandconn.Executeto a WinCC alarm for traceability.
11. Edge Cases and Field-Proven Caveats
-
32-bit vs 64-bit mismatch: WinCC runtime is 32-bit; if you install the 64-bit-only ODBC Driver 17 on a 64-bit runtime host, the driver will not be visible to the 32-bit
odbcad32.exeinSysWOW64. Always install both (32- and 64-bit) driver variants on dual-platform hosts. -
Named pipes vs TCP/IP: If the connection string omits
Network Library, the driver will try named pipes first on local connections. Across hosts, force TCP:Network Library=DBMSSOCN. -
MARS and lingering cursors: If you use
adUseServercursors and fire many open recordsets, exhaustion of the connection pool can manifest as Timeout expired. Switch toadUseClient(CursorLocation = 3) and disconnect the recordset from the connection withrs.ActiveConnection = Nothing. - SQL Server Express Advanced Services: Free SQL Server Express limits the database size to 10 GB per database (2017–2022). For multi-shift production logging, plan for SQL Server Standard.
-
Anti-virus interference: Some endpoint protection suites block
odbcad32.exeor inject DLLs intomsado15.dll. Add the WinCC install directory and%windir%\SysWOW64\odbcad32.exeto the AV exclusion list. -
Regional settings: Decimal separator mismatch between WinCC station and SQL Server locale can corrupt floating-point inserts. Force
Use Settings for Visual Basicor pass parameters rather than concatenated strings. -
Always close: WinCC's VBScript host is multi-threaded across HMI screens; failing to
Set conn = Nothingat the end of every script leaks connections and triggers Pool exhausted within hours.
12. Quick Reference Card
| Task | Action | Where |
|---|---|---|
| Find provider name | Use MSOLEDBSQL for SQL 2017+; SQLNCLI11 for SQL 2012/2014 |
WinCC VBScript connection string |
| Create DSN |
odbcad32.exe → System DSN → Add |
%windir%\SysWOW64\odbcad32.exe |
| Test DSN | Test Data Source… button | ODBC administrator |
| Open from VBS | conn.Open connStr |
WinCC script editor |
| Enable SQL TCP | SQL Server Configuration Manager → TCP/IP → Enable | SQL host |
| Verify session | SELECT * FROM sys.dm_exec_sessions WHERE program_name='WinCC_RT' |
SSMS |
| Siemens FAQ | Entry 61883659 (WinCC VBS/SQL), Entry 61886098 (SQL setup) | Siemens Support |
Where do I find the provider name for my SQL Server data source in WinCC?
The provider string is set in the WinCC VBScript connection string. For modern SQL Server (2017+) use Provider=MSOLEDBSQL; for legacy SQL Server 2012/2014 use Provider=SQLNCLI11; for a generic fallback through ODBC use Provider=MSDASQL together with a System DSN named WinCC_SQL (or your custom name). The provider itself is not stored in the DSN — it is selected by the script at ConnectionString open time.
How do I create an ODBC data source on a WinCC runtime PC?
Open the 32-bit ODBC administrator with Win+R → %windir%\SysWOW64\odbcad32.exe (WinCC runtime is a 32-bit process), switch to System DSN, click Add…, pick ODBC Driver 18 for SQL Server, enter a DSN name, the SQL Server hostname\instance, choose authentication, set the default database, and click Test Data Source…. Confirm with Siemens FAQ 61886098.
Why do I receive error 0x800A0E7A "Provider cannot be found" from WinCC VBScript?
The ProgID in the Provider= token does not match an installed OLE DB provider, or the ODBC driver it depends on is missing. Install the OLE DB Driver 18 for SQL Server, confirm the spelling (MSOLEDBSQL, not MSOLDEDBSQL), and verify the provider is registered with regedit under HKLM\SOFTWARE\Classes\MSOLEDBSQL.
What is the difference between WinCC V7.x and WinCC Advanced for SQL access?
WinCC V7.x (classic SCADA) ships with its own Microsoft SQL Server (embedded or external) and uses ODBC for archive redundancy. WinCC Advanced / Professional (TIA Portal HMI) has no built-in database; SQL access is provided exclusively from VBScript via OLE DB or ODBC. The VBS connection-string syntax is identical, but the engineering tool (SIMATIC Manager vs TIA Portal) and the runtime architecture differ. Refer to Siemens FAQ 61883659 for the canonical VBS/SQL examples.
Can WinCC VBScript use Windows Authentication to SQL Server?
Yes. Replace the UID and PWD parameters with Integrated Security=SSPI. The WinCC runtime process must run under a Windows account that has a SQL Server login mapped via Active Directory or a local certificate. Note that the Windows service account for WinCC Runtime is not always your interactive account — verify it with whoami /all from an elevated command prompt while WinCC Runtime is running.