TFDQuery.Prepare cannot determine parameter types for INSERT query on MS SQL SERVER

前端 未结 2 1313
执念已碎
执念已碎 2020-12-20 05:42

I open a TFDConnection for MS SQL Server with parameters:

DriverID=MSSQL
Password=test
User_Name=test
Server=VS2003-2008
Database=test
Single Co         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 06:41

    I would follow help here and avoid calling Prepare before parameters are defined (their data types are fully specified). You haven't missed anything but this note from help:

    It is recommended to setup parameters before the Prepare call.

    For common ODBC drivers (you are still talking to an ODBC driver, no matter if they internally uses OLE DB to communicate with the DBMS), FireDAC doesn't determine parameter data types for the prepared command. Instead, it prepares command statement on the target DBMS and tries to bind existing ones from the Params collection. That's how the Prepare method is implemented (Tokyo).

    ODBC API provides the SQLDescribeParam function to obtain parameter details for the prepared command, but FireDAC doesn't use it anywhere (at this time). Instead, it leaves building parameter collection manually. Which is not wrong, because in the end, it is the developer who needs to know which value to assign to a certain command parameter so as to know this value type.

提交回复
热议问题