Hi, I have a workflow using node-red-contrib-msg-queue 1.0.2 and node-red-contrib-mssql-plus 0.10.2 with node-red v20.1.0.
I am trying to store the message if the MSSQL connection goes down using the status block to check the MSSQL node. However the message is always stored even if the MSSQL server is available. I have tried removing the queue node and the data gets written to the database. Any ideas how to deploy this workflow to function correctly? Here is my code. Thanks.
[
{
"id": "61625aaf.479d84",
"type": "inject",
"z": "b8807c3ae6f9ae7c",
"name": "{\"count\": 5, \"age\": 35}",
"props": [
{
"p": "payload",
"v": "{\"count\": 5, \"age\": 35}",
"vt": "json"
},
{
"p": "topic",
"v": "",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"count\": 5, \"age\": 35}",
"payloadType": "json",
"x": 280,
"y": 220,
"wires": [
[
"58ed799b9a02ceae"
]
]
},
{
"id": "6e09980a.127878",
"type": "MSSQL",
"z": "b8807c3ae6f9ae7c",
"mssqlCN": "a51e405c.10f64",
"name": "",
"query": "PRINT @name\n\nSELECT TOP {{{payload.count}}} * \nFROM testdb.dbo.[MyTable] WHERE Name = @name\n\nSELECT TOP {{{payload.count}}} * \nFROM testdb.dbo.[MyTable] WHERE Age = @age\n\nPRINT 'complete'",
"outField": "payload",
"x": 700,
"y": 220,
"wires": [
[
"babb6d0.5ae7e9"
]
]
},
{
"id": "babb6d0.5ae7e9",
"type": "debug",
"z": "b8807c3ae6f9ae7c",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 890,
"y": 220,
"wires": []
},
{
"id": "bed23a904c8705f5",
"type": "status",
"z": "b8807c3ae6f9ae7c",
"name": "",
"scope": [
"6e09980a.127878"
],
"x": 280,
"y": 400,
"wires": [
[
"61b4684c06ffbe55"
]
]
},
{
"id": "61b4684c06ffbe55",
"type": "function",
"z": "b8807c3ae6f9ae7c",
"name": "Check the status message text",
"func": "// Function node\nif (msg.status) {\n // Check the status message text\n if (msg.status.text === 'requesting') {\n // If the status is \"requesting\", it means the connection is connected\n msg.payload = \"Connected\";\n } else if (msg.status.text === 'Error') {\n // If the status is \"Error\", it means there is an error in the connection\n msg.payload = \"Disconnected\";\n } else {\n // If the status is neither \"requesting\" nor \"Error\", handle other cases here if needed\n msg.payload = \"Unknown Status\"; // Or provide an appropriate message\n }\n} else {\n // If there is no status object, handle other cases here if needed\n msg.payload = \"No Status Information\"; // Or provide an appropriate message\n}\n\n// Pass the modified message along to the next node\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 530,
"y": 400,
"wires": [
[
"58ed799b9a02ceae"
]
]
},
{
"id": "58ed799b9a02ceae",
"type": "queue",
"z": "b8807c3ae6f9ae7c",
"name": "Message Queue",
"connected": "Connected",
"connectedType": "str",
"disconnected": "Disconnected",
"disconnectedType": "str",
"sqlite": "C:\\sqlite\\mydatabase.db",
"x": 520,
"y": 220,
"wires": [
[
"6e09980a.127878"
]
]
},
{
"id": "a51e405c.10f64",
"type": "MSSQL-CN",
"tdsVersion": "7_4",
"name": "My SQL Server",
"server": "192.168.1.38",
"port": "1433",
"encyption": false,
"database": "testdb",
"useUTC": false,
"connectTimeout": "15000",
"requestTimeout": "15000",
"cancelTimeout": "5000",
"pool": "5",
"credentials": {}
}
]