# SQL-DB Client Connect

This function block is used to configure and establish a connection to a SQL database (MySQL, PostgreSQL, MSSQL, SQLite). Use it to create a persistent database client that other blocks can use to run queries or perform data operations.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

This function block does not have input sockets.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`DB Client` A reusable database client object that other blocks (for example `SQL-DB Operations`) can use to execute queries and transactions.

`Connection Success` A boolean indicating whether the connection was established successfully.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Database Type` A dropdown to choose the kind of database (MySQL, PostgreSQL, MSSQL, SQLite). Choosing `SQLite` will simplify the UI because no host/port/user/password are required.

`Host` Hostname or IP address of the database server. Hidden for `SQLite`.

`Database` Database name. For `SQLite` this field is used as the database file path.

`Port` TCP port of the database server. Hidden for `SQLite`.

`User` Database username. Hidden for `SQLite`.

`Password` Database password. Hidden for `SQLite`.

Note: Changing any of these fields will reset the existing connection and trigger a new connection attempt when the block is evaluated.

## 🎯 Features <a href="#features" id="features"></a>

* Simple multi-database support with a single, unified UI for common SQL backends.
* `SQLite` compatibility with reduced fields when a file-based database is selected.
* Outputs a ready-to-use `DB Client` and a `Connection Success` flag for downstream logic and error handling.
* Automatic reconnection when configuration changes are detected.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. Select `Database Type` that matches your server.
2. Fill in `Host`, `Port`, `User`, `Password`, and `Database` as appropriate (for `SQLite` provide the file path in `Database`).
3. Run your scenario or evaluate the block. The block will attempt to connect and will set `Connection Success` accordingly.
4. Use the provided `DB Client` with `SQL-DB Operations` to perform queries, inserts, updates, or other database tasks.
5. If you change any connection fields, the block will reset the current connection and attempt to reconnect on next evaluation.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When evaluated, the block validates the provided parameters and attempts to establish a connection. On success it exposes a reusable client via the `DB Client` output and sets `Connection Success` to true. On failure it logs an error and sets `Connection Success` to false.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Combine with `SQL-DB Operations` to run queries and return results into the flow.
* Use `Data to JSON` to serialize complex results before writing them to files or sending them over a network.
* Use `CSV Export` or `Image Logger` (for image-related metadata) to persist results coming from database queries.
* Use `Data Write Local` or `Data Write Global` to store the `DB Client` or recent query results for reuse across different parts of your project.
* Use `Debug Input` to inspect raw outputs from `SQL-DB Operations` while building and troubleshooting your scenario.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Connection fails but credentials are correct: verify network access to `Host` and that the selected `Port` is open and accepting connections.
* Using `SQLite`: ensure the path provided in `Database` is accessible and the application has file permissions to read/write that file.
* If configuration changes appear not to take effect: edit any control (for example `Host`) to force the block to reset and re-establish the connection.
* If you need to confirm returned data while developing, attach `SQL-DB Operations` and `Debug Input` to inspect responses before integrating them further.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/input-output/communication/sql-db-client-connect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
