How to connect to NexusDB from Delphi using UniDAC
In today's dynamic software development world, creating robust and flexible database connections is essential for building efficient applications. When developing in Delphi, the ability to integrate with databases like NexusDB can significantly enhance performance and productivity. Using UniDAC (Universal Data Access Components), Delphi developers can establish connections with NexusDB quickly and efficiently, without the complexity of native drivers.
What is UniDAC
UniDAC is a library of components designed by Devart to provide quick and error-free data access to a wide range of database management systems (DBMS). It allows Delphi and C++Builder developers to connect their applications to various databases without needing to write different code for each database type.
What is NexusDB
NexusDB is a high-performance, scalable, and flexible database engine designed for use in Delphi and C++Builder applications. It is a SQL-based, embeddable database that provides both local and client-server modes, making it suitable for a wide range of applications, from small desktop apps to large, multi-user systems.
Connect to NexusDB from Delphi via UniDAC
Set up the NexusDB provider in RAD Studio
- RAD Studio installed on your system
- NexusDB components installed for the corresponding IDE
- NexusDB connection details
- UniDAC from Devart installed
Step 1. Rebuild and reinstall the NexusDB provider in RAD Studio 12
Before using the NexusDB provider with RAD Studio 12, you must rebuild and reinstall the provider package.
1. Compile the NexusDB provider package.
1.1 Open RAD Studio.
1.2 Open the NexusDB provider package file:
- Select File > Open.
- In the dialog that opens, navigate to the .dpk file location. For example:
C:\Program Files (x86)\Devart\UniDAC for RAD Studio 12\Source\NexusDBProvider\Delphi29\nexusprovider290.dpk.
3. Right-click the package in the Project Manager and select Compile. The package will be compiled within the RAD Studio.

Step 2. Copy the NexusDB provider library to the system directory
2.1 Close RAD Studio.
2.2 Copy and paste the nexusprovider290.bpl file from the directory: C:\Users\AllUsers\Documents\Embarcadero\Studio\23.0\bpl
and paste it into the system directory: C:\Windows\SysWOW64
Configure connection to NexusDB using UniDAC
1. Reopen your RAD Studio.
2. Select File > New > Windows VCL Application - Delphi to create a new Delphi project.

3. Add the TUniConnection component.
3.1 Navigate to the Component palette and find the UniDAC category.
3.2 Drag and drop the TUniConnection component onto the Form Designer.

4. Double-click the UniConnection1 label on the form, and in the dialog that opens, configure the following TUniConnection properties:
- In the Provider dropdown list, select NexusDB.
- In the Database field, enter the path to your NexusDB database or a NexusDB alias. Once done, return to the Connect tab.
NexusDB connection modes:
- Embedded mode: In this mode, the application integrates the NexusDB engine directly, and no external server is required. To connect in the embedded mode, leave the Server field blank and provide the file path to the database in the Database field.
- Server mode: In this mode, the application connects to a standalone NexusDB server that manages the databases. To connect in the server mode, specify the server's hostname or IP address in the Server field, and provide the database alias in the Database field.
5. Click Connect.

Configure connection to NexusDB from the Code Editor
You can use the TUniQuery or TUniTable UniDAC components to interact with NexusDB: execute SQL queries, and access data. Below is an example of how to configure a connection to a NexusDB database in your code.
procedure TForm1.ConnectToNexusDB; begin UniConnection1.ProviderName := 'NexusDB'; UniConnection1.Database := 'your-database-path'; // Specify the path to your NexusDB database UniConnection1.Options.Values['TableExtension'] := 'nx1'; UniConnection1.LoginPrompt := False; try UniConnection1.Connect; ShowMessage('Connection successful!'); except on E: Exception do ShowMessage('Failed to connect: ' + E.Message); end; end;
You can place this code within a method that you call when your form is created or when a specific event is triggered.
Access and manage NexusDB data with UniDAC at design time
Retrieve NexusDB data visually in RAD Studio
In RAD Studio, you can visually design and configure application components, forms, and user interfaces without running the application or writing a single line of code. Likewise, you can retrieve and manipulate NexusDB data at design time using UniDAC—simply configure the data components visually.
1. Add the TUniQuery and TUniDataSource components: go to the Component palette and find the UniDAC category. Then, drag and drop the components onto your form.
2. Add the TNexusDBUniProvider component: drag and drop the TNexusDBUniProvider component onto your form from the UniDAC Providers category.
3. Similarly, add the TButton component from the Standard category and TDBGrid from the Data Controls category.

4. Optional: Rename the buttons and labels as needed.
- To rename a button, right-click it and select Quick Button Configuration. In the dialog that opens, enter the new name for the button in the Caption field and click OK.
- To rename a label, select it in the Form Designer. Then, in the Object Inspector, locate the Name property and assign the desired value to it.
5. Double-click the UniQuery1 label in the Form Designer and enter a query to select the data from a NexusDB database. For example:
SELECT * FROM DEPT;
6. Click OK to save changes and close the dialog.

7. Click the UniDataSource1 label in the Form Designer and set the DataSet property to the UniQuery1 value in the Object Inspector.
8. Select the UniQuery1 label in the Form Designer, and in the Object Inspector, set the Active property to True. You will see the query result instantly.

Manipulate NexusDB data visually in RAD Studio
In the same way, you can modify NexusDB data at design time without needing to write any code.
1. Add a new TUniQuery component to the Form Designer. Or you can modify modify the existing one.
2. Select the UniQuery1 component in the Form Designer, and in the Object Inspector, set the Active property to True.
3. Double-click the UniQuery1 component in the Form Designer and enter a query to insert, delete, or update data in the NexusDB database. For example:
INSERT INTO dept (DEPTNO, DNAME, LOC) VALUES (70, 'FINANCE', 'COLORADO');
4. Click Execute, then click OK to close the dialog.
5. Check the result.

In a similar way, you can delete or update data in a NexusDB database.
Work with NexusDB data using UniDAC at runtime
Access NexusDB data using code
To select data from NexusDB at runtime using UniDAC, you can use the TUniQuery component, which provides a flexible way to execute SQL queries and fetch data.
1. Add the TUniQuery, TUniDataSource, and TNexusDBUniProvider components to your form.
2. Click the UniDataSource1 label in the Form Designer and set the DataSet property to the UniQuery1 value in the Object Inspector.
3. Double-click the UniQuery1 label in the Form Designer and enter a query to select the data from a NexusDB database.
4. Click OK to save changes and close the dialog.
5. Execute the query at runtime.
Example code in Delphi:
procedure TNexuDB_Demo.btOpenClick(Sender: TObject); begin ViewData.Open end;
Insert, update, or delete NexusDB data at runtime
Insert data
To insert data into a NexusDB table at runtime, use the INSERT INTO SQL statement. You can set up parameters for dynamic values.
Example code in Delphi:
procedure TNexuDB_Demo.InsertIntoDept; begin UpdateData.Connection := NexusDBConnection; // Link the query to the connection UpdateData.SQL.Text := 'INSERT INTO DEPT (DEPTNO, DNAME, LOC) VALUES (:DEPTNO, :DNAME, :LOC)'; // Assign parameter values UpdateData.ParamByName('DEPTNO').AsInteger := 60; UpdateData.ParamByName('DNAME').AsString := 'MARKETING'; UpdateData.ParamByName('LOC').AsString := 'PHILADELPHIA'; try UpdateData.Execute; // Execute the query ShowMessage('Data inserted successfully!'); except on E: Exception do ShowMessage('Failed to insert data: ' + E.Message); end; end;
Update data
To modify existing records, use the UPDATE SQL statement with a WHERE clause to target specific rows.
Example code in Delphi:
procedure TNexuDB_Demo.UpdateDept; begin UpdateData.Connection := NexusDBConnection; // Link the query to the connection UpdateData.SQL.Text := 'UPDATE DEPT SET DNAME = :DNAME, LOC = :LOC WHERE DEPTNO = :DEPTNO'; // Assign parameter values UpdateData.ParamByName('DNAME').AsString := 'SALES'; UpdateData.ParamByName('LOC').AsString := 'NEW YORK'; UpdateData.ParamByName('DEPTNO').AsInteger := 60; try UpdateData.Execute; // Execute the query ShowMessage('Data updated successfully!'); except on E: Exception do ShowMessage('Failed to update data: ' + E.Message); end; end;
Delete data
To delete records, use the DELETE FROM SQL statement with a WHERE clause to specify which rows to remove.
Example code in Delphi:
procedure TNexuDB_Demo.DeleteFromDept; begin UpdateData.Connection := NexusDBConnection; // Link the query to the connection UpdateData.SQL.Text := 'DELETE FROM DEPT WHERE DEPTNO = :DEPTNO'; // Assign parameter value UpdateData.ParamByName('DEPTNO').AsInteger := 60; try UpdateData.Execute; // Execute the query ShowMessage('Department deleted successfully!'); except on E: Exception do ShowMessage('Failed to delete data: ' + E.Message); end; end;
NexusDB-specific options
Although UniDAC provides a unified interface for interacting with various database servers, it also allows you to fine-tune its behavior for specific sources, including NexusDB. This flexibility is achieved through server-specific options. These options can be configured for components such as:
- TUniConnection
- TUniQuery
- TUniTable
- TUniStoredProc
- TUniSQL
- TUniLoader
You can access these options via the SpecificOptions property, which is a string list. To assign a value to a specific option, use the following syntax:
ComponentName.SpecificOptions.Values['OptionName'] := 'OptionValue';
For example:
UniConnection.SpecificOptions.Values['CommandTimeout'] := '10'; UniQuery.SpecificOptions.Values['FetchAll'] := 'True';
You can find detailed descriptions of the allowed options in our Documentation center.
Benefits of UNIDAC's NexusDB-specific options
- Performance tuning
- Enhanced reliability
- Custom behavior
Fine-tune options like FetchAll and ServerCursor to balance memory usage and speed.
Options like HeartbeatInterval and LostConnectionTimeout improve connection stability.
Options like ReadOnly and DirectLoad allow customization for specific use cases.
By using these NexusDB-specific options, you can optimize your application for robust and efficient data access using UniDAC in Delphi.
Conclusion
UniDAC offers an efficient solution for connecting Delphi applications to NexusDB databases. Its robust feature set, including server-specific options, simplifies database management and enhances the performance of your applications.
By combining NexusDB's high-performance architecture with UniDAC's flexibility and ease of use, you can create scalable, efficient, and reliable applications. Start using UniDAC with NexusDB today to simplify database connectivity, enhance productivity, and unlock the full potential of your Delphi projects.