The communication is ok. If I close SQL Server, I get this error:
Can not connect.
If I start it, I have no error message, but still not has any effect on the data base. I try to INSERT INTO a new record.
Server name: KI_OROS\SQLEXPRESS
Database name: MyFirstDatabase
Datatable name: MyFirstTable
I try to send this packet: INSERT INTO MyFirstTable (ID) VALUES (99)
I am totally beginner with SQL Server, what am I doing wrong?
You can't just connect to SQL Server over TCP and send queries as text.
Clients talk to a SQL Server over TCP using the Tabular Data Stream protocol. It starts with a handshake to negotiate what capabilities both support, then the client authenticates with the server ("logging in") and only after that you can send your SQL string, within an SQL batch.
How to implement that, see [MS-TDS]: Tabular Data Stream Protocol. But you don't want to implement that yourself.
My goal is to write a PLC program , which can communicate directly with the sql server
Either use a library that allows you to execute SQL statements from code, or let your PLC execute an HTTP request (which is trivial using plain text) to a service that accepts this message and executes the necessary SQL.