简体   繁体   中英

Query with SQL Server 2008 R2 with FireDAC

I'm new to Firedac but not with Delphi

I can make a connection with SQL Server, and when I connect, there is no problem. I get connection OK. It works with code, with the wizard and with the FireDAC explorer.

The name of the database is :

C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\MSSQL.1\MSSQL\DATA\3410b539-431f-4dff-ad0d-a574d1b13498.MDF

I'm stuck with a simple query.

SELECT * 
FROM Account;

This query works from within the FireDac explorer but not from my program, I'm getting the following error:

[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Could not find server 'C:\\PROGRAM FILES (X86)\\MICROSOFT SQL SERVER\\MSSQL' 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.'

I'm also also getting the same error, when I try to do it from the UI within Delphi.

To try the query, I dropped onto the form a TFDQuery, the connection property was set automatically to the unique connection on the form. Then I set the query with the query editor, I get the error when I click on execute.

With code it like this :

FDConnection1.Connected := true;
FDQuery1.Close;
FDQuery1.SQL.Text := 'select * from Account;';
FDQuery1.Active := True;

When I debug the program, I get the error when setting the query active.

I see that the name of the DB is not complete in the error message. But it's complete in the component settings

Please advise,


I tried some extra test : If I run the query from the UI editor (double-clicking on the FDConnection, Tab SQL Script), type the query, it works :-).

But when I try to do it on the FDQuery component, with the connection assigned to previous FDConnection, I get the same error. It' like some parameters are missing.

You are using the location of the SQL data file, instead of the name of the SQL Database.

If you do not know the name you can use the wizard to try and find it.

(Sorry could not add comments yet. This is also mentioned by Jens in the comments)

Update: if that is really the name, try enclosing it in [ ].

I got this response from an Embarcadero engineer:

The problem is not in FireDAC, but in SQL Server ODBC driver SQLPrimaryKeys function. It fails to work with a catalog name containing a dot. FireDAC uses this function to get primary key fields for a result set, when fiMeta is included into FetchOptions.Items. So, as a workaround / solution, please exclude fiMeta from FetchOptions.Items.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM