Search code examples
sql-serverrestdelphidelphi-10-seattlemormot

Can't correctly setup SQL Server connection in mORMot


I try to setup connection to SQL Server and catch the error

var
  GFireDACConnProp : TSQLDBFireDACConnectionProperties;
  GFFireDACConn: TSQLDBFireDACConnection;
begin
  try
    GFireDACConnProp := TSQLDBFireDACConnectionProperties.Create('MSSQL?Server=server','dbname','user','pass');
    GFFireDACConn := TSQLDBFireDACConnection.Create(GFireDACConnProp);
    // OR  I := GFireDACConnProp.Execute('Select * from Station', []);
    GFFireDACConn.Connect;
....

Error message:

Project app_.exe raised exception class Exception with message 'Object factory for class {3E9B315B-F456-4175-A864-B2573C4A2101} is missing. To register it, you can drop component [TFDPhysXXXDriverLink] into your project'.

What is correct way to connect to SQL Server and expose REST service?


Solution

  • FireDAC is more helpful than some other frameworks in that when things go wrong the exception messages often say how to fix the problem.

    So, in your case, given that the message says "you can drop component [TFDPhysXXXDriverLink] into your project" the thing to try first would be to drop the relevant DriverLink component onto your form/datamodule. As you're using Sql Server, the the driver link to choose would be the TFDPhysMSSqlDriverLink, which is on the FireDAC Links tab of the Component Palette.

    If you're creating a Console application, obviously there's no form or datamodule to drop the link on. In that case, create it in code:

    FDPhysMSSQLDriverLink := TFDPhysMSSQLDriverLink.Create(Nil);