// Creates new connection or gets previously used from the session public DataConnection GetConnection(EntitySession session, DbConnectionLifetime connLifetime = DbConnectionLifetime.Operation, bool admin = false) { if (admin) { return(new DataConnection(session, this.Settings, connLifetime, true)); } var conn = session.CurrentConnection; if (conn != null) { if (conn.Lifetime < connLifetime) { conn.Lifetime = connLifetime; } return(conn); } // if we have KeepOpen mode (recommended in Web app), then make Lifetime explicit - // i.e. until explicitly called to close; web call context handler will do it after completing // processing requests if (session.Context.DbConnectionMode == DbConnectionReuseMode.KeepOpen) { connLifetime = DbConnectionLifetime.Explicit; } conn = new DataConnection(session, this.Settings, connLifetime, admin: admin); session.CurrentConnection = conn; //it will register it in disposables return(conn); }
public DataConnection(EntitySession session, DbSettings settings, DbConnectionLifetime lifetime, bool admin = false) { Session = session; DbSettings = settings; Lifetime = lifetime; var connString = admin ? settings.SchemaManagementConnectionString : settings.ConnectionString; DbConnection = settings.Driver.CreateConnection(connString); }