通过FireDac(Delphi)连接到MS SQL LocalDB时出错

时间:2016-09-30 16:03:03

标签: delphi localdb firedac

连接参数:

Server=(LocalDb)\MSSQLLocalDB
DriverID=MSSQL
ODBCAdvanced=AttachDbFileName=C:\Dir\Dir\TestDB.mdf

连接成功。

像FDConnection.ExecSQLScalar(' SELECT ....')这样的请求 - 效果很好 通过TFDScript重新获取 - 运作良好

但运行TFDQuery会产生以下错误:

[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Could not find server 'C:\Dir\Dir\TestDB' in sys.servers.
Verify that the correct server name was specified. 
If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.

1 个答案:

答案 0 :(得分:2)

只需将Database = any_name添加到连接字符串。

Server=(LocalDb)\MSSQLLocalDB
DriverID=MSSQL
ODBCAdvanced=AttachDbFileName=C:\Dir\Dir\TestDB.mdf
Database=MyDatabase