This article is only applicable to .NET 6 and later, and is not applicable to eXtremeDB for .NET Framework
This sample shows how to built embedded .NET core application using SQL and native database. It can use pure IM database configuration and disk based configuration.
To build disk database 4 memory devices are created:
Database.Device: PrivateMemoryDevice (or SharedMemoryDevice if shared memory is used) for IM part and cache and FileDevice for disk database part and transaction log. IM segment is used in disk database to keep system data, and to keep transient objects.
To use the database a database connection is required, even if database is built in the same process as a code using it. To connect to the database we use instance of SqlLocalConnection class:
SqlLocalConnection con = db.ConnectSql();
Note that table is created dynamically with:
con.ExecuteStatement("create table MyTable (pk int primary key, value varchar)");
And note that this is a transactional operation and it is done inside transaction block.
This sample shows how to use remote SQL client to the xsql server started outside of this executing process. It can be started either on the same machine or of another machine in the network.
To run this sample a running instance of the XSQL server is required.
Unlike local Sql case here we don’t create database, we only connect to it. But anyway Database class is required as it controls eXtremeDB environment, f.e. load runtime libraries, controls data marshaling, etc. So we start from creation of Database instance:
Database db = new Database(mode, binPath);
Devices are not needed here as we don’t allocate any memory.
Then we connecting to the remote server:
SqlRemoteConnection con = db.ConnectRemoteSql(host, port, maxAttempts);
And then we operating in the same way as when using local in-process database.