简体   繁体   中英

Using SQL Server connection string with firedac

Using Delphi 10.2, I am trying to use a standard SQL Server connection string with Firedac, but can't seem to make it work.

This is my connection string:

Data Source=PSI-PC006\MSSQL2008;Initial Catalog=PlayGround;Integrated Security=True;Pooling=False;

My code is simply:

function tdmMain.doConnect(const connection : string) : boolean;
begin
  dmConnect.cnxData.ConnectionString := connection;
  dmConnect.cnxData.DriverName := 'MSSQL';
  try
      dmConnect.cnxData.Connected := true;
      result := true;
  except
      on E:Exception do
      begin
        ShowMessage('Connection error' + e.Message);
        result := false;
      end;
  end;
end;

I am trying to make it so that I don't have to load from an ini file, that my application can just be called with the connection string.

Is this even possible?

You don't need to do what you are trying, in order to set up the connection string.

Just double-click your FDConnection1 in the IDE form editor then, in the "FireDAC Connection Editor" pop-up, on the Definition tab, just fill in the parameters you need to specify to make the connection.

Using the FireDAC Connection Editor sets the Params property of your FDConnection. If you want to adjust the FD equivalent of the MSSS Connection String at runtime, you can do direct assignments to the parameter values as per usual.

The FireDac connection string is not same as a SQL Server connection string. It also includes the driver name so you do not need to do that separately.

Server=PSI-PC006\MSSQL2008;OSAuthent=Yes;Database=PlayGround;DriverID=MSSQL

If you use the connection configuration dialog box in the Delphi UI you can see the name=value pairs by clicking on the .. to the right of the Parameters property. The connection string is just those name=:value pairs separated by semicolons.

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