If you need to choose which data provider for SQLite to use with dotConnect Universal, we recommend using dotConnect for SQLite because of its obvious advantages. This article provides a brief overview of dotConnect for SQLite, describes some useful features and helps you get started quickly.
dotConnect for SQLite is a full-featured 100% managed ADO.NET data provider for the .NET Framework and the .NET Compact Framework. dotConnect for SQLite is acknowledged as the leading ADO.NET data provider for SQLite, and it has many advantages over any rival product. The main features of dotConnect for SQLite are:
The full list of dotConnect for SQLite features can be found on the product page.
Developer Edition of dotConnect Universal includes dotConnect for SQLite as a bundled provider. Trial Edition includes trial dotConnect for SQLite Data Provider as well. For Express Edition of dotConnect Universal, dotConnect for SQLite should be purchased and installed separately.
dotConnect Universal is compatible with dotConnect for SQLite version 2.00 and above.
To deploy applications written with dotConnect Universal, copy the run-time assemblies Devart.Data.Universal.dll and Devart.Data.Universal.SQLite.dll to target machine. If you are using the standalone (not bundled) dotConnect for SQLite Data Provider, you will also have to deploy its Devart.Data.SQLite.dll assembly.
These assemblies can be registered at the Global Assembly Cache (GAC) for the appropriate .NET Framework or placed in the folder of your application.
For web projects, you may also need to deploy the Devart.Data.Universal.Web.dll, Devart.Data.SQLite.Web.dll and App_Licenses.dll assemblies. The *.Web.dll assemblies are required for using the ASP.NET Provider Model and the App_Licenses.dll assembly is a part of licensing mechanism.
Web projects are usually run as partially trusted code. The following permissions are required by dotConnect Universal and dotConnect for SQLite: medium trust plus ReflectionPermission.
Suppose you want to connect in Direct mode to the D:\TestApplication\database.db database and want to create the database in case it does not exist. In this case your connection string would look like this:
Data Source=D:\TestApplication\database.db;FailIfMissing=False;
The following table enumerates most important connection string parameters.
| Name | Description |
|---|---|
| Attach | Specifies the list of databases to attach, separated with semicolons. |
| Automatic Index | Determines whether SQLite automatic indexing is enabled. The default value is true. |
| AutoVacuum | Determines what happens when a transaction that deletes data from a database is committed. |
| Binary GUID | Determines how GUIDs are stored. If true, GUID columns are stored in binary form; otherwise, GUID columns are stored as text. |
| Busy Timeout | Sets an SQLite busy handler that sleeps for a specified amount of time (in milliseconds) when a table is locked, until at least the specified sleep time has accumulated. |
| Cache Size | Specifies the maximum number of database disk pages to cache. The default value is 2000. |
| Cache Spill | Determines whether to allow spilling dirty cache pages to the database file in the middle of a transaction. The default value is true. |
| Case Sensitive Like | Determines whether the LIKE operator performs case-sensitive comparison. The default value is false. |
| Cell Size Check | Determines whether to perform additional checks on database b-tree pages as they are initially read from disk. The default value is false. |
| Checkpoint FullFSync | Determines whether the F_FULLFSYNC syncing method is used during checkpoint operations on systems that support it. The default value is false. |
| Connect Timeout -or- Connection Timeout | Specifies the length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. The default value is 15. |
| Connection Lifetime | Specifies the maximum lifetime (in seconds) of a pooled connection. When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span exceeds the value specified by Connection Lifetime. The default value is 0 (connection always returns to pool). |
| Count Changes | Determines whether the database engine returns the number of inserted, updated, or deleted rows. |
| Data Source | Specifies the path and name of the SQLite database file to which to connect. This parameter supports both file system paths and URI format. |
| DateTime Format | Specifies the format of DATETIME values. If set to "Ticks", DATETIME values are expressed in ticks; otherwise, DATETIME fields are formatted according to ISO8601. |
| Default Command Timeout | Specifies the time (in seconds) to wait while trying to execute a command before terminating the attempt and generating an error. A value of 0 indicates no limit. |
| Enable Load Extension | Determines whether an SQLite extension library can be loaded from a named file using the SELECT load_extension(file_name) statement. Useful, for example, for full-text search modules. |
| Encryption | Determines whether the database is encrypted and kind of the database encryption. |
| Encryption License Key | Specifies the license key for database encryption features. |
| Enlist | Determines whether the connection is automatically enlisted in the current distributed transaction. The default value is true. |
| FailIfMissing | Determines what to do when the database file is missing. If true, an exception is thrown when the database file cannot be found; otherwise, an empty database is created. |
| Foreign Key Constraints | Determines whether foreign key constraints are enforced. |
| Full Column Names | Determines whether query result column names are returned in the fully qualified "table.column" form. |
| Full FSync | Determines whether the F_FULLFSYNC syncing method is used on systems that support it. |
| Ignore Check Constraints | Determines whether check constraints are enforced. The default value is false. |
| Initialization Command | Specifies a database-specific command that should be executed immediately after establishing the connection. |
| Journal Mode | Determines the SQLite journal mode used for the connection. |
| Journal Size Limit | Specifies the maximum size (in bytes) of the journal file. If the journal file exceeds this size after commit, it is truncated. Negative values mean no limit. The default value is -1. |
| Legacy File Format | Determines whether backwards compatibility of the database file is enabled. |
| Load Extension | Specifies the list of SQLite extension libraries to load when the connection opens. Applied only when the Enable Load Extension parameter is set to true. |
| Locking | Determines the database locking mode used for the connection. |
| Max Page Count | Specifies the maximum number of pages allowed in the database file. |
| Max Pool Size | Specifies the maximum number of connections allowed in the pool. Setting the Max Pool Size value of the ConnectionString can affect performance. The default value is 100. |
| Min Pool Size | Specifies the minimum number of connections allowed in the pool. The default value is 0. |
| Page Size | Specifies the page size (in bytes) used for newly created databases. Must be a power of two between 512 and 8192 inclusive. |
| Password | Specifies the password for the encrypted database. |
| Persist Security Info | Determines whether security-sensitive information, such as the password, is retained in the connection string after the connection has been opened. |
| Pooling | Determines whether, by default, the connection object is drawn from the appropriate pool or is created and added to the appropriate pool. The default value is true. |
| Read Uncommitted | Sets the process isolation level. The default level is SERIALIZABLE (false). |
| ReadOnly | Determines whether to open the database in read-only mode. An exception is thrown if the database does not exist. Available only if the connection uses UTF8 encoding. |
| Recursive Triggers | Determines whether recursive triggers are turned on. The default value is false. |
| Reverse Unordered Selects | Determines whether the result of a SELECT statement without an ORDER BY clause is retrieved in the reverse of its normal order. The default value is false. |
| Run Once Command | Specifies a database-specific command that should be executed immediately after establishing the connection. Unlike Initialization Command, it is not executed for connections obtained from the connection pool. |
| Secure Delete | Determines whether to overwrite the deleted data with zeroes. |
| Short Column Names | Determines whether query result column names are returned without a table name qualifier. |
| SQLiteCryptLicenseKey | Specifies the software license key for the SQLiteCrypt extension. Required when connecting to an SQLiteCrypt-encrypted database. |
| Synchronous | Determines the synchronization mode used for write operations. |
| Temp Store | Determines the location of temporary files: the user's TEMP folder, a custom folder, or RAM. |
| Temp Store Directory | Specifies the directory where temporary files are stored. The default value is an empty string, which indicates the current Windows user's temp directory. |
| Threads | Specifies the maximum number of auxiliary threads a prepared statement can launch to assist with a query. The default value is 0, which means no auxiliary threads are allowed. |
| Transaction Scope Local | Restricts all connections within a TransactionScope object to a single internal connection when several connections use the same connection string. The default value is false. |
| User Id | Specifies the user name used to authenticate when connecting to an encrypted database. |
| UTF16 | Sets the UTF16 encoding for the connection when set to true; otherwise, UTF8 encoding is set. |
| Validate Connection | Specifies whether to validate connections that are retrieved from the pool. |
| Version | Specifies the database version. |
| WAL Auto Checkpoint | Specifies the write-ahead log auto-checkpoint interval: the number of write-ahead log pages after which a checkpoint is performed. |
| Writable Schema | Determines whether the SQLITE_MASTER table can be changed using UPDATE, INSERT, and DELETE statements. Editing the SQLITE_MASTER table this way can result in a corrupt database file. |
To get up and running quickly, you have to perform the following steps:
That's all you need to start executing queries on the server. Below is a code fragment that illustrates steps 2-5. It also shows how to perform INSERT and SELECT operations.
dotConnect for SQLite does not support the UniSQL except the IF operator. Use SQLite predefined macro to build conditional UniSQL statements. For more information refer to the UniSQL topic.
The following table shows how the UniDbType enumeration maps to the SQLite database type.
| UniDbType | SQLite data type |
|---|---|
| BigInt | BIGINT |
| Binary | BLOB |
| Bit | SMALLINT |
| Blob | BLOB |
| Boolean | SMALLINT |
| Byte | SMALLINT |
| Char | TEXT |
| Clob | TEXT |
| Currency | DOUBLE |
| Date | DATETIME |
| DateTime | DATETIME |
| Decimal | DOUBLE |
| Double | DOUBLE |
| Guid | TEXT |
| Int | INT |
| NChar | TEXT |
| NClob | TEXT |
| NVarChar | TEXT |
| Single | DOUBLE |
| SmallInt | SMALLINT |
| TinyInt | SMALLINT |
| Time | DATETIME |
| TimeStamp | DATETIME |
| VarChar | TEXT |
| Xml | TEXT |
The national character encoding (NChar, NClob types) in the fields is not supported by SQLite server. However, you can achieve same effect with the Unicode=true connection string parameter.
For more information on dotConnect for SQLite Data Provider please visit the following locations:
Using dotConnect Universal with SQL Client | Using dotConnect Universal with dotConnect for Oracle | Using dotConnect Universal with dotConnect for PostgreSQL | Using dotConnect Universal with dotConnect for MySQL