Connection String

SQLDatabase.Net library connection string is a string that specifies information about the data source and other information about the database file, it is used by the library as means of connecting to it.

it is based on several different sections in the form of key and value, all keys and values are supplied as string, each key value pair is separated by semi colon (;) and format is Key = Value ; . The connection string can also be built using SqlDatabaseConnectionStringBuilder class, see example code on how to use it. The only required part is Datasource or URI which can be either file://FileFullPath or @memory for in memory database. Disk I/O error means unable to read write to specified directory or path. Make sure you have Read and Write permissions such as on directory or files. e.g. in ASP.NET App_Data folder require IIS_IUSRS , IUSER or ASP.NET user to have read write permissions. Similarly on desktop the user will need proper permissions.

Available options (keys and values)

"SchemaName={schema name} ; Uri=file://{File full path} ; MultipleActiveResultSets = {true or false} ; ExtendedResultSets = {True or False } ; Mode = {ReadOnly or ReadWrite} ; FileMode = {OpenIfExists or OpenOrCreate} ; "


Version 2.7 and greater: supports COLLATION keyword in connection string with default being Binary which enforce case sensitivity on string comparison A = a as false. Nocase removes cases sensitivity to match A = a as true. To enforce case sensitivity or case insensitivity across all operating systems, use COLLATION keyword in the connection string with option of Binary, NoCase, CurrentCulture , CurrentCultureIgnoreCase , InvariantCulture , InvariantCultureIgnoreCase , Ordinal , OrdinalIgnoreCase. For best performance use BINARY or NOCASE. The default collation can be overwritten in WHERE clause using COLLATE keyword. See example SQL Examples at Github

Connection String Example

Android / Xamarin Path Creation

var WriteAbleFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var dbfilepath = System.IO.Path.Combine(WriteAbleFolder, "afile.db");
using (SqlDatabaseConnection cnn = new SqlDatabaseConnection("uri=file://" + dbfilepath + ";"))

string ConnectionString = "SchemaName = db;";
ConnectionString += "MultipleActiveResultSets = true;";
ConnectionString += "ExtendedResultSets = true;";
ConnectionString += "Mode = readwrite;";
ConnectionString += "FileMode = OpenIfExists;";
ConnectionString += "URI = file://" + ExampleDatabaseFile + ";";

The @memory keyword can be used to open in memory database connection, such databases lasts only during the life time of connection object and are lost when connection is closed disposed or goes out of scope.
string ConnectionString = "SchemaName = db;";
ConnectionString += "MultipleActiveResultSets = true;";
ConnectionString += "ExtendedResultSets = true;";
ConnectionString += "Mode = readwrite;";
ConnectionString += "FileMode = OpenIfExists;";
ConnectionString += "URI = @memory;";

C# Connection String Example

// NO semi colon (;) termination
SqlDatabaseConnectionStringBuilder BuildConnectionString = new SqlDatabaseConnectionStringBuilder()
{
 DatabaseFileMode = DatabaseFileMode.OpenIfExists,
 DatabaseMode = DatabaseMode.ReadWrite,
 SchemaName = "db",
 Uri = "Full File Path Goes Here"
};
            
using (SqlDatabaseConnection cnn = new SqlDatabaseConnection(BuildConnectionString.ConnectionString))
            {
cnn.Open();
            }

-- Provided via ConnectionString property
using (SqlDatabaseConnection cnn = new SqlDatabaseConnection())
            {
                cnn.ConnectionString = BuildConnectionString.ConnectionString;
cnn.Open();
            }