TFDQuery.Prepare无法确定MS SQL SERVER上INSERT查询的参数类型 [英] TFDQuery.Prepare cannot determine parameter types for INSERT query on MS SQL SERVER

查看:187
本文介绍了TFDQuery.Prepare无法确定MS SQL SERVER上INSERT查询的参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为MS SQL Server打开一个 TFDConnection ,其参数为:

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

然后我创建一个 TFDQuery (运行时),将其连接设置为上面,并用参数化的INSERT查询填充它:

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,...)

然后我调用Prepare for query并获取:

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

如果我对FireBird数据库也是如此,没有问题。

我想它与使用OLEDB有关。该计算机上没有本机MS SQL客户端。

数据模块中 TFDConnection 的FDPhysMSSQLDriverLink 没有。 code>驻留,但是添加一个没有区别。

表TT_ACT存在。

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?

推荐答案

我将在此处关注帮助,避免致电 准备 ,然后再定义参数(它们的数据类型已完全指定)。除了帮助,您什么都没有错过:

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:


建议在准备之前设置参数

对于常见的ODBC驱动程序(您仍在与ODBC驱动程序进行通讯,无论它们内部是否使用OLE DB与之通信DBMS),FireDAC不会为准备好的命令确定参数数据类型。相反,它在目标DBMS上准备命令语句,并尝试从 Params 集合。这就是 准备 方法已实现(东京)。

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提供了 SQLDescribeParam 函数可获取准备好的命令的参数详细信息,但FireDAC不会在任何地方使用它(此时)。取而代之的是,它手动留下建筑参数集合。没错,因为最后,是开发人员需要知道将哪个值分配给某个命令参数才能知道该值的类型。

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.

这篇关于TFDQuery.Prepare无法确定MS SQL SERVER上INSERT查询的参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆