Skip to content

Explicitly passing the connection

Zev Spitz edited this page Mar 4, 2019 · 1 revision

All the methods on SqlString have overloads which take a DbConnection. This is useful when you don't want to set the global ConnectionFactory property, or you are using multiple connections:

using (var conn1 = new OleDbConnection(connectionString1)) {
    using (var conn2 = new OleDbConnection(connectionString2)) {
    
        @"CREATE TABLE Persons (
            ID COUNTER PRIMARY KEY, 
            LastName TEXT,
            FirstName TEXT
        )".AsSql().Execute(conn2);
        
        // ...
    }
}
Clone this wiki locally