You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Delphi Alexandria 11.3下FireDAC通过ODBC连SQL Server失败求助

问题描述

需要通过INI配置文件实现dbExpress与FireDAC均使用ODBC连接SQL Server,原因是SQL Server不再支持原生客户端DLL远程连接。此前在Delphi 10 Seattle中已成功配置dbExpress连接,但在Delphi Alexandria 11.3中配置FireDAC连接时遇到问题:

当前使用的连接字符串:

Database=QCLocal;Server=PV06;DriverID=ODBC;DataSource=qcLocal13;MonitorBy=Remote;MARS=yes;OSAuthent=no;User_Name=ccm;Password=ccm

连接时抛出异常:

Project LoginTest.exe raised exception class EODBCNativeException with message '[FireDAC][Phys][ODBC][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified'.
(qcLocal13确实存在且拼写正确)

还尝试了以下几种连接字符串配置:

  • 配置1:
Database=QCLocal;DriverID=ODBC;ODBCDriver=ODBC Driver 13 for SQL Server;DataSource=qcLocal13;MonitorBy=Remote;User_Name=ccm;Password=ccm
  • 配置2:
Database=QCLocal;DriverID=ODBC;ODBCDriver=ODBC Driver 13 for SQL Server;DataSource=qcLocal13;Server=PV06;MonitorBy=Remote;User_Name=ccm;Password=ccm
  • 配置3:
Database=QCLocal;DriverID=ODBC;ODBCDriver=ODBC Driver 13 for SQL Server;Server=PV06;MonitorBy=Remote;User_Name=ccm;Password=ccm

以上三种配置均抛出异常:

Project LoginTest.exe raised exception class EODBCNativeException with message '[FireDAC][Phys][ODBC][Microsoft][ODBC Driver 13 for SQL Server]Neither DSN nor SERVER keyword supplied'.

另有配置:

Database=QCLocal;DriverID=ODBC;Server=PV06;MonitorBy=Remote;User_Name=ccm;Password=ccm

对应抛出异常:

Project LoginTest.exe raised exception class EODBCNativeException with message '[FireDAC][Phys][ODBC][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified'.

uses子句已包含FireDAC.Phys.ODBC、FireDAC.Phys.ODBCDef,询问遗漏了什么配置及解决方法。

解决方案

1. 确认DSN与程序位数匹配

Delphi Alexandria默认编译64位程序,若你创建的qcLocal13是32位DSN,ODBC管理器会无法找到它:

  • 打开对应位数的ODBC数据源管理器:
    • 32位程序:运行C:\Windows\SysWOW64\odbcad32.exe
    • 64位程序:运行C:\Windows\System32\odbcad32.exe
  • 检查qcLocal13是否存在于对应列表中,若不存在则重新创建对应位数的DSN。

2. 修正FireDAC连接字符串格式

FireDAC对ODBC参数的解析有明确规则,分两种模式调整:

模式一:依赖DSN连接

此时不要指定ODBCDriver(否则会切换到无DSN直连模式),正确字符串为:

DriverID=ODBC;DataSource=qcLocal13;OSAuthent=no;User_Name=ccm;Password=ccm;MonitorBy=Remote;MARS=yes

注:Database参数可省略,因为DSN已配置好目标数据库。

模式二:无DSN直连

无需依赖DSN,直接指定驱动、服务器和数据库信息,字符串格式:

DriverID=ODBC;ODBCDriver=ODBC Driver 13 for SQL Server;Server=PV06;Database=QCLocal;User_Name=ccm;Password=ccm;MonitorBy=Remote;MARS=yes

此时不要添加DataSource参数,避免参数冲突。

3. 验证ODBC驱动安装

检查系统是否已正确安装ODBC Driver 13 for SQL Server,驱动位数需与程序编译位数(32/64位)匹配,若未安装或版本不兼容,重新安装对应驱动。

4. 确保FireDAC初始化正确

程序启动时需完成FireDAC的初始化,可在initialization段添加代码:

initialization
  FDManager.Initialize;

或通过IDE的FireDAC配置向导生成初始化代码,避免因组件未初始化导致连接失败。


内容的提问来源于stack exchange,提问作者Connie McBride

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:23:22