Remote server is unreachable, possible problems can be:
- Server is turned off
- Server is in different subnet than PLC and gateway is wrong
- Firewall is setup wrongly. See chapter 2.1.6 in User Guide
- Server is not configured for TCP/IP communication. See chapter 2.1.7 in User Guide or check this video.
- sIpAddress contains Hostname such as ‘localhost’ or ‘TestSQLServer’
Whole process how to activate license can be found here.
Load into your PLC with Codesys Runtime Example project with fbMsSQL library. Load it to your CPU and run project. On output of this block you will find variable sMacAddress with MAC Address which is used for licensing.
Connect to PLC in TIA Portal choose Online&Diagnostics -> then Diagnostics and in Manufacturer information is Serial number.
MsSQL Library for SoMachine needs to setup SEC(placeholder M2xx PLCSystem).
Go to Library Manager open by + sign on Microsoft SQL Library for SoMachine, here you will find SEC with ?. Then Click on Placeholders.
Here you need to find placeholder SEC and change Placeholder resolution from Default to set by you.
There you need to go to Controller -> Type of your CPU(M241,M251, etc.) and there find PLCSystem and click on OK and OK and Rebuild.
Note! Dollar sign($) is needed if you are using ‘ in string and if you want to store string into database N$’Your_string$’.
INSERT INTO [dbo].[Table_TEST] ([text]) VALUES (N$’Hello World 🙂$’)
Example of command to how to insert datetime to MsSQL database:
EXEC sp_insertData @TIMESTAMP = N$’2016-11-12 19:45:33$’, @Value= 12
EXEC sp_insertData – execution stored procedure sp_insertData which is declared on MsSQL Server. Note! If you will create stored procedure on MsSQL Server side, don’t forget to setup execute permission to user which is used on PLC.
@TIMESTAMP= N$’2016-11-12 19:45:33$’ – inserting datatime to database as a string value, but in PLC string has to be used dollar sigh($) before ‘.
@Value = 12 – is just normal integer value
Create FIFO buffer with appropriate datatype(e.g. strings), which will work with State machine and execute commands one by one.
Best approach is to create state machine such as CASE structure with states:
- Login(set xConnect to true) after trigger
- Execute batch of commands(set xExecuteSQL to true)
- Disconnect(set xDisconnect to true)
There is more possible ways:
If you are trying:
- Log to database– tTimeout means that it failed and you get error and you have to try it again with different parameters according error message.
- Executing Query– tTimeout means that command failed in some step and you have to try repair query due to error
Basically timeout check if the state machine is longer time in some step. So 1s is enough if you have local database. For instance if I’m connecting from Czech Republic to Amazon SQL Server in Oregon, sometimes it can exceed 1s.
We will provide you free of charge new activation number for new PLC.
Yes, library will work with any PLC S7-1200 (from FW 4.0) and S7-1500 (from FW 1.8) programmed with TIA Portal V13, V14 & V15.
FW 3.0 on S7-1200 is old HW architecture which doesn’t support some commands used in MsSQL Library.
No, this is Single License library. So for every PLC where you will use this library, you need to have new license. License is bind to SN of PLC.