Technical Forum

SIMATIC WinCC flexible

Read SQL database using wincc flexible problem

Thread Starter: NMax   Started: 4/29/2013 9:20 AM   Replies: 4

« Previous thread Next thread »
Page 1 of 1 (5 items)
  4/29/2013, 9:20 AM
Joined 4/8/2013
Last visit: 6/12/2013
Posts: 18
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hello,


but the entries aren't shown up in RT. can someone please check my sript and point out where i'm doing wrong?

The table have 4 columns.First column is a datetime variable,2nd column int, 3rd comun int, 4th column string..17 entries can be shown in one time. this is the script i use to read out the data.



Dim conn, rst, SQL_Table
Dim i,j

On Error Resume Next

Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")


conn.Open "Provider=MSDASQL;Initial Catalog=Machine_1;DSN=MachineArchive" 


If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear 
Exit Sub
End If

SQL_Table = "SELECT * FROM " & szTableName 
             
            
Set rst = conn.Execute(SQL_Table)


If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear 
Exit Sub
End If

If Not (rst.EOF And rst.BOF) Then 
rst.MoveFirst 
j=0
Do
j=j+1
rst.MoveNext
Loop Until rst.EOF
rst.MoveFirst 
If nbTab>=j-17 Then
nbTab=j-17
End If
If nbTab<j-17 Then
For i=1 To nbTab
rst.MoveNext
Next
End If
If nbTab<0 Then
nbTab=0
End If
For i=1 To 17
SmartTags("Table\Value_" & i & "_0") = rst.Fields(0).Value
SmartTags("Table\Value_" & i & "_1") = rst.Fields(1).Value
SmartTags("Table\Value_" & i & "_2") = rst.Fields(2).Value
SmartTags("Table\Value_" & i & "_3") = rst.Fields(3).Value 
rst.MoveNext
Next
rst.close 
Else
ShowSystemAlarm "No entries are available."
End If


conn.close

Set rst = Nothing
Set conn = Nothing




there is no data shown out in wincc and i didn't get any message error, so i dont know where i'm doing wrong.

Thank you in advance.

Nmax



=== Edited by NMax @ 4/29/2013 9:31 AM [GMT ] ===


=== Edited by NMax @ 4/29/2013 9:30 AM [GMT ] ===


Top
  4/29/2013, 11:49 AM
Joined 9/5/2011
Last visit: 5/7/2014
Posts: 3037
Rating:
Rated: Outstanding [3.8 out of 5 / rated 157 time(s)]. (157) 
Users with special expertise supervising conferences
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hello,

Here you can find more about database and WinCC flexible.

How do you access an SQL database in WinCC flexible via a script?

Tweety
Top
  4/29/2013, 12:06 PM
Joined 4/8/2013
Last visit: 6/12/2013
Posts: 18
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
thank you for your reply..

i have refered to that entry before. 
Does anyone know where i'm doing wrong? 

Nmax
Top
  4/30/2013, 1:37 PM
Joined 9/5/2011
Last visit: 5/7/2014
Posts: 3037
Rating:
Rated: Outstanding [3.8 out of 5 / rated 157 time(s)]. (157) 
Users with special expertise supervising conferences
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hello,

I used the example on this link.
How do you access an SQL database in WinCC flexible via a script?

It works good, without any problems.

Tweety
Top
  4/30/2013, 4:27 PM
Joined 4/8/2013
Last visit: 6/12/2013
Posts: 18
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hello Tweety,

To archive data/values from WinCC RT into SQL database, is it correct to use this command below?

SQL_Table = "INSERT INTO " & szTableName & " (SPEED, TEMPERATURE, ERROR)" _
           & "VALUES (" & Speed & ", " & Temp & ", ' " & szError & " ' )"

SPEED,TEMPERATURE, and ERROR are the colums name.
Speed,Temp and szError are the tags. szError is string type and the other two are decimal.

I put this command just after CREATE TABLE commands..the table is created but i got an error "Incorrect syntax near ',' "

Could you help me, please? Thank you in advance

Regards,
NMax
Top
Page 1 of 1 (5 items)
Actions