Skip to main content
1-Visitor
August 27, 2019
Question

MSSQL Extension mapping table name syntax error

  • August 27, 2019
  • 1 reply
  • 1916 views

I create SQL command for purge all data in table.

 

DELETE FROM [[tableName1]];

[[tableName1]] is the input table.

 

When execute this service. It error like below code

Unable to Invoke Service purgeTable on MTH.FC2.ASSY.SQLConnector : Execute Update failed: com.microsoft.sqlserver.jdbc.SQLServerException: Must declare the table variable "@P0".

But, If I put the table name inside the service code. It can execute without error.

DELETE FROM test;	

 

How I should to do ?

1 reply

18-Opal
August 27, 2019

Hello,

 

Take a look at this article, and in particular check Example 3, it should do the trick. Also you may find <<tableName>> to work -- it does simple string replacement, but I'm not sure if it still works in the recent versions of ThingWorx and with MS SQL.

 

...and then forget about it, because it is a very bad idea, unless you are OK about somebody dropping your entire database one day. If you really need to do it, then wrap it into some parameter-sanitizing code and make sure that only system admins can execute it.

 

Regards,
Constantine

1-Visitor
August 28, 2019

It's not workingUntitled.png