I open a TFDConnection
for MS SQL Server with parameters:
DriverID=MSSQL
Password=test
User_Name=test
Server=VS2003-2008
Database=test
Single Connection=TRUE
Max Cursors=256
USE OLEDB=TRUE
I then create a TFDQuery
(run time), set its connection to the above, fill it with an parameterized INSERT query:
insert into TT_ACT (TT_ACT_ID,TT_PARENT_ID,TT_FROMDATE,TT_TODATE,TT_NAME,TT_NR,TT_CODE,TT_GROUP...)
values (:TT_ACT_ID,:TT_PARENT_ID,:TT_FROMDATE,:TT_TODATE,:TT_NAME,:TT_NR,:TT_CODE,:TT_GROUP,...)
I then call Prepare for the query and get:
[FireDAC][Phys][MSSQL]-335 Parameter [TT_ACT_ID] data type is unknown.
Hint: Specify TFDParam.DataType or Assign TFDParam.Value before Prepare/Execute call
If I do the same for a FireBird database there are no issues.
I guess it has something to do with using OLEDB. There is no native MS SQL client on the machine.
There is no FDPhysMSSQLDriverLink
on the datamodule where the TFDConnection
resides, but adding one makes no difference.
Table TT_ACT exists.
What am I forgetting to make this work?
command.Parameters.Add("@ID", SqlDbType.Int);
– GurevichXSQLVAR
variables when the command is prepared (they parse command and returns collection of what is needed) whilst with ODBC you must explicitly ask for parameter descriptions for the prepared command (by callingSQLDescribeParam
) which does not happen in FireDAC. But I wouldn't treat that as issue, because in the end, it is the developer who fills out the parameter collection and they must know what they do (which data types they use for which values they fill in). If it gets prepared doesn't change much. – PreponderatePrepare
, you should not (maybe must not) modify parameter data types (that's what drivers want). If you access values byAs<T>
accessor, you can expect exception like this, because you're saying, "hey FireDAC, set me this value into parameter that is supposed to be of type T" whilst on the other hand you expect fetching parameter collection "all-inclusive". – Preponderate