pkg_sql_socket_connection version: 1.1.21

Published 2025-09-04

ruud

sdk | dart
repository | svn
platform | generic
status | n/a
  • Readme
  • Changelog
  • Versions

SqlServerSocket

HuigHaverlag managed copy of SqlServerSocket

graph

Connects to Microsoft SQL Server from the Dart language.

Connection to SQL Server is achieved by the use of a specific service (SqlServerSocket.exe -- included here) that runs in the background and has to be started before the Dart program.

With this library you can run SQL queries on the server and have them returned as native Dart objects (Lists, Maps) with the correct data types.

There is also a dedicated class Table that simplifies CRUD operations on datasets without the need to writw SQL queries for insert, update or delete.

How to install it

  1. Install and execute SqlServerSocket.exe in the background on the server machine where SQL Server is installed. The program will listen for connection coming from Dart on the local port 10980.

  2. On the Dart side (server), install and reference the package sql_server_socket.

Basic usage

Some Dart examples (using async and await):

// creates a connection
var conn = new SqlConnection("SERVER=localhost;Database=mydb;Trusted_connection=yes");

// open connection
await conn.open();

// runs a query returning a single value
var howmany = await conn.queryValue("SELECT COUNT(*) FROM Customers");

// runs a query returning a single row
var myFirstCustomer = await conn.querySingle("SELECT name,age FROM Custormers");
print(myFirstCustomer["name"]);

// runs a query returning all rows
var customers = await conn.query("SELECT TOP 10 name,age FROM Custormers");
for(var customer in customers)
{
   print(customer["name"]);
}

// execute a command, returning the number of rows affected
var n = await conn.execute("UPDATE Customers SET age=0");
print("zeroed $n customers");

// disconnect
await conn.close();

SQL string formatting

When writing SQL queries, strings, booleans and datetimes needs to be formatted according to the SQL Server syntax. You can use these helper functions in your string interpolations:

  • sqlBool()
  • sqlString()
  • sqlDate()

Example:

var custName = "J'EROME";
var accept = true;
var v = await conn.queryValue("""
                 SELECT COUNT(*)
                 FROM Customers
                 WHERE Name = ${sqlString(custName)}
                       AND TimeStamp > ${sqlDate(new DateTime.now())}
                       AND AcceptFlag = ${sqlBool(accept)}
                """);

Using the Table object

Complex datasets operations can be done by the use of the Table object. It handles row inserts, deletes and updates, sending to the database only the changed data and retrieving identity values after inserts.

Example:

var conn = new SqlConnection("SERVER=localhost;Database=mydb;Trusted_connection=yes");

await conn.open();

// populates a table
Table cust = await conn.queryTable("SELECT Id, Name, Age FROM Customers");

// add a new customer to table
var row = cust.newRow();
row["Name"] = "Steve";
row["Age"] = 33;
cust.rows.add(row);

// save changes to databases
await cust.post();

// "Id" field, previously 0, has now the identity number assigned by the database
print("newly inserted customer has Id ${row['Id']}");

// update customers
cust.rows[0]["Age"] = 42;
await cust.post();

// delete customers
cust.rows.removeAt(0);
await cust.post();

await conn.close();

Notes

https://github.com/nippur72/SqlServerSocket

https://stackoverflow.com/questions/37616521/how-can-i-connect-to-sqlserver-running-on-virtualbox-from-my-host-macbook#:~:text=Create%20a%20new%20Login%3A%20right,the%20SQL%20Server%20authentication%20option.&text=Configure%20the%20Firewall%20on%20the,probably%20not%20the%20best%20option.)

https://www.connectionstrings.com/sql-server/

Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;

Changelog

1.1.21 - 2025-09-04

Fixed

  • Unawaited futures.

1.1.20 - 2024-12-19

Changed

  • Version bump from 1.1.19 to 1.1.20 (Support Apple silicon (arm64)).

1.1.19 - 2024-08-22

Changed

  • Version bump from 1.1.18 to 1.1.19 (SDK update 3.5.1).

1.1.18 - 2024-03-13

Changed

  • Server.cs does no cleanup after disconnect anymore to prevent crashes.

1.1.17 - 2024-03-13

Added

  • pkg_woonzorg_source_parser application port.

1.1.16 - 2024-02-01

Changed

  • Version bump from 1.1.15 to 1.1.16 (Resolve package version confusions).

1.1.15 - 2023-05-22

Fixed

  • Wrong async constructs.

1.1.14 - 2023-04-13

Fixed

  • await unawaited futures.
  • Marked some futures unawaited.

1.1.13 - 2023-03-30

Fixed

  • Off-by-one error that prevented receiving data, due to change from substring to getRange.

1.1.12 - 2023-02-09

Changed

  • Version bump from 1.1.11 to 1.1.12 (Version confusion after compiler bug chaos).

1.1.11 - 2022-12-27

Changed

  • Version bump from 1.1.10 to 1.1.11.

1.1.10 - 2022-12-22

Changed

  • Version bump from 1.1.9 to 1.1.10.

1.1.9 - 2022-12-22

Changed

  • Version bump from 1.1.8 to 1.1.9 (Recompile due to installer optimizations).

1.1.8 - 2022-11-23

Added

  • SqlApplicationPorts::flutter_da_preprocess.

1.1.7 - 2022-10-19

Changed

  • Removed all print statements for logging.
  • Enabled mediabase test suites.

1.1.6 - 2022-10-11

Changed

  • Version bump from 1.1.5 to 1.1.6 (Recompile due to wrong GetIt.instance syntax.).

1.1.5 - 2022-10-05

Changed

  • Version bump from 1.1.4 to 1.1.5 (fixed pdflib searchpath macos crash).

1.1.4 - 2022-10-01

Changed

  • Version bump from 1.1.3 to 1.1.4 (pkg_pdflib bundle macos dylib).

1.1.3 - 2022-09-30

Changed

  • Made pure dart.

1.1.2 - 2022-09-29

Changed

  • Version bump from 1.1.1 to 1.1.2 (dependencies upgraded).

1.1.1 - 2022-08-31

Changed

  • removed various finals due to new linter rules.

1.1.0 - 2022-08-25

Changed

  • You must now provide an application-specific port to communicate with the mono service application.

1.0.1 - 2022-08-25

Changed

  • Example now kills the process on application close. (see windowManager in the source).

1.0.0 - 2022-07-25

Changed

  • First major version.

0.0.1+2 - 2022-02-25

Changed

  • Unknown changes.

0.0.1 - 2022-02-25

Changed

  • Initial version.

1.1.21

2025-09-04 download

1.1.20

2024-12-19 download

1.1.19

2024-08-22 download

1.1.18

2024-03-13 download

1.1.16

2024-02-01 download

1.1.15

2023-05-22 download

1.1.14

2023-04-13 download

1.1.13

2023-03-30 download

1.1.12

2023-02-09 download

1.1.11

2022-12-27 download

1.1.10

2022-12-22 download

1.1.9

2022-12-22 download

1.1.8

2022-11-23 download

1.1.7

2022-10-19 download

1.1.6

2022-10-11 download

1.1.5

2022-10-05 download

1.1.4

2022-10-01 download

1.1.3

2022-09-30 download

1.1.2

2022-09-29 download

1.1.1

2022-08-31 download

1.1.0

2022-08-25 download

1.0.0

2022-07-25 download