Wincc Tutorial4/23/2021
You can either watch the video tutorial or read the step by step tutorial.Video Step By Step There are two authentication ways to connect to a SQL Server database, they are Windows Authenticaion and SQL Authentication.In this article WinCC will connect using the Windows Authentication, but I show the connection string to connect to SQL Server using SQL Authentication.Note: In this article I assume you have already installed SQL Server.
![]() I have used the SQL Server 2008, but all the steps done here are valid for SQL Server 2005. For this article, I have created a database, so we can read from and insert into it. For many real cases, the plant or system already has a database. Creating a SQL Server Database On Database right-click and then click on New Database. On Database name: type SQLWINCC (or whatever the name you want) Under Database SQLWINCC right-click on New Table. Note: I have not created indexes or primary keys in the Table1 because SQL Server configuration is not the focus of this article But in a real system it is highly recommended to create them. ![]() The WinCC Explorer must look like this Creating Internal Tags In WinCC Explorer under WinccSql double-click on Tag Management Click on Tag Management Internal Tags and create these 12 tags. Some of them will keep the data from SQL Server and others will write keep the values to insert into SQL Server. Configuring Screen In WinCC Explorer under WinccSql double-click on Graphics Designer. Using Rectangle, Static Text and IO Fields objects dispose them like this. ![]() Creating the VB-Scripts Introduction The easiest way to communicate with a databases is using VB-Script and it basically takes 4 steps. Connection Configuration Command Configuration Recordset Configuration Manager the data returned from database The Connection Configuration has basically these parameters: Provider Data Sourver (Server Name) Initial Catalog (Database you want to connect to) Authentication In this article I am using this connection string: ProviderSQLOLEDB;Data SourceMAWINWINCC;InitialCatalogSQLWINCC;Trustedconnectionyes; The Trustedconnection indicates the connection will be done by Windows authentication. For a SQL Authentication the connection string would be like this: ProviderSQLOLEDB;Password1234567890;Persist Security InfoTrue;User IDsqluser;Initial CatalogSQLWINCC;Data SourceMAWINWINCC VB-Script for Insert Button Click on Insert button and browse to Events Static Text Mouse Mouse Click VBS-Action. VB-Script for Select Button Click on Select button and browse to Events Static Text Mouse Mouse Click VBS-Action. Now copy this scipt there Dim cn connection object Dim rs record set object Dim mc command objet Dim i Dim sql Dim column1 Dim column2 Dim column3 Dim column4 Set cn CreateObject ( ADODB.Connection ) Set rs CreateObject ( ADODB.Recordset ) Set mc CreateObject ( ADODB.Command ) It is the adUseClient Enumetaror and indicates that a client-side is to be used cn.CursorLocation 3 Connection String cn.ConnectionString ProviderSQLOLEDB;Data SourceMA1815WINCC;Initial CatalogSQLWINCC;Trustedconnectionyes; Open connection cn.Open In this article I have limitted to 2 registers, just for my convinence, but you could read some data from SQL and then wirte them in a grid, for example. TAGSTRINGn1 HMIRuntime.Tags.Item( TAGSTRING i 1 ).Write column1 TAGINT12 or TAGINT22 or. TAGINTn2 HMIRuntime.Tags.Item( TAGINT i 2 ).Write column2 TAGINT13 or TAGINT23 or. TAGINTn3 HMIRuntime.Tags.Item( TAGINT i 3 ).Write column3 TAGINT14 or TAGINT24 or.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |