Delphi : Connecting with SQL Server using FireDAC

Search for a command to run...

No comments yet. Be the first to comment.
ASP.NET Core Configuration Guide Overview ASP.NET Core uses a layered configuration system where later sources override earlier ones for the same key. Configuration Priority Order Priority Source
Legacy Delphi applications often struggle with outdated UI/UX, performance issues, and monolithic architectures that make refactoring difficult. However, a full rewrite is not always feasible due to time, cost, and the risk of disrupting critical bus...
Entity Framework Core (EF Core) is a powerful and flexible object-relational mapping (ORM) framework for .NET applications, enabling developers to work with relational databases using strongly-typed .NET objects. It simplifies data access by abstract...

In this article we are going to cover some advance scenarios where Options pattern is very useful. We have covered the basic understanding of Options pattern into Options pattern in ASP.NET Core: Introduction article. Please go through it if not fami...

In this article we will learn about Options pattern in ASP.NET Core for dealing with application configurations. The Options pattern uses the C# classes to access and manage the configurations thus providing more flexibility and type safe approach to...

FireDAC is universal data access library which provides a common API to connect with different database back-end , maintaining the access to database specific features and without compromising on performance. FireDAC enables native high-speed access to almost all enterprise database including no SQL databases such as MongoDB
In this article we will connect MS SQL Server database with Delphi using FireDAC. We will go through code to make database connection.
Go to Delphi IDE and select File -> New -> VCL Form application - Delphi


uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait,
FireDAC.Phys.MSSQLDef, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL, Vcl.StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
private
{ Private declarations }
FDBConnection: TFDConnection;
FMSSQLDriverLink: TFDPhysMSSQLDriverLink;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.
Note the units added to uses clause related to components used in the application.
procedure TForm2.Button1Click(Sender: TObject);
begin
try
FMSSQLDriverLink := TFDPhysMSSQLDriverLink.Create(nil);
FDBConnection := TFDConnection.Create(nil);
FDBConnection.Params.DriverID := 'MSSQL';
FDBConnection.Params.UserName := 'sa';
FDBConnection.Params.Password := '<your_password>';
FDBConnection.Params.Database := '<your_database>';
FDBConnection.Params.Add('server=<your_DB_server>');
FDBConnection.Connected := True;
if FDBConnection.Connected then begin
ShowMessage('Connected successfully');
end;
finally
if FDBConnection.Connected then begin
FDBConnection.Close;
end;
end;
end;
This is very basic steps to connect with SQL server using FireDAC, let me know your thoughts in comment.
I have prepared a YouTube video to show a demo of Delphi - MSSQL connection Connect Delphi with MSSQL database using FireDAC