Accessing SQL-database from wincc

Csar1985

Member
Join Date
Sep 2009
Location
Eeklo
Posts
11
Hi,

i was wondering,

we are currently connecting to a database from wincc flex lik described on the siemens site:

https://support.automation.siemens....extranet=standard&viewreg=WW&load=treecontent

Now, we are switching onto regular wincc, and those scripts doesnt seem to work. Has anyone got experience with connecting to a sql database from wincc?

We use the database for storing info on our clearing conditions.
Tnx in advance
Nico
 
I do quite a bit of data logging to SQL.
Siemens uses the ODBC route, I do not.
I use the generic OLEDB provider, and a stored procedure that resides on the SQL DB.

Example

On Error Resume Next
'Variable for server connection
Dim strProvider, strServer, strDatabase, strUID,strPWD
Dim objConn, objCMD, objParams

'Variable for server connection
strProvider = "SQLOLEDB"
strServer = "YourServerName"
strDatabase= "ME"
strUID ="UserName"
strPWD ="password"

'Create connection with SQL server
Set objConn = CreateObject("ADODB.Connection") 'Create object for sql connection
objConn.ConnectionTimeout = 5
objConn.Open "Provider="+ strProvider+";Server="+ strServer+";DataBase="+ strDatabase+";UID="+ strUID+";PWD="+ strPWD+";"

'Create the command send to server
Set objCMD = CreateObject("ADODB.Command") 'Create cammand object for stored procedure call from SQL
Set objCMD.ActiveConnection = objConn 'Pointer to show cammand which connection to use
objCMD.CommandText = strProcName 'Name of the stored Procedure
objCMD.CommandType = 4 'adCmdStoredProc

'Parameters for the stored procedure (name,type,direction,size,value)
'Input parameters for procedure

Set objParams = objCMD.CreateParameter("@YourParameter",3,1,1,Parameter)
objCMD.Parameters.Append objParams
objCMD.Execute

'Returned Values
' Transfer returned Values
'Close connection and Release variables
objConn.close
Set objConn = Nothing
Set objCMD = Nothing
Set objParams = Nothing


One thing to remember if your WinCC PC is not getting a DNS from a DNS server, you will have to at the server name and IP address to the host file.
Or you could use the server IP address insted of the servers actual name.

Hope this help.
 

Similar Topics

Hi all, I am having issues accessing my Cimplicity software - the site code changed after re-install and I am no longer able to attain a new key...
Replies
10
Views
195
For the past few day, I have had problems accessing the Rockwell Knowledgebase. When I try to access it (and I do have a TechConnect Support...
Replies
7
Views
419
Hi, Small issue i've really been beating myself up over today. I've been working with Panelview panels for years. Currently working on an older...
Replies
1
Views
596
Dear experts, I have the following setup: CPU-313C (6ES7313-5BF03-0AB0 V2.6) + CP343-1 (6GK7343-1EX30-0XE0 V2.0) communicating with Siemens PC...
Replies
7
Views
2,733
I'm looking to replace an AB PanelView 600 2711-K6C2 HMI with a C-more EA9-T10WCL. The PLC in the system is a SLC 5/03, which is staying. I...
Replies
2
Views
1,255
Back
Top Bottom