Skip to content

Connection reuse

Zev Spitz edited this page Mar 4, 2019 · 4 revisions

The standard use case is to have ConnectionFactory return a new connection each time it is called, thus running each statement on its own connection. If you want to reuse the same connection, you have two choices:

  • Set the ConnectionFactory to return the same connection each time, instead of a new connection

    using (var conn = new OleDbConnection(connectionString)) {
        ConnectionFactory = () => conn;
        
        @"CREATE TABLE Persons (
            ID COUNTER PRIMARY KEY, 
            LastName TEXT,
            FirstName TEXT
        )".AsSql().Execute();
        
        // ...
    }
  • Explicitly pass in the connection to the methods on SqlString

Clone this wiki locally