protected virtual AuthenticatedSession OnAuthenticate(string defaultSchema, string username, string password) { var user = Database.AuthenticateUser(username, password, RemoteEndPoint); if (user == null) { return(null); } IDatabaseConnection connection = Database.CreateNewConnection(user, OnTriggerFired); // Put the connection in exclusive mode LockingMechanism locker = connection.LockingMechanism; locker.SetMode(LockingMode.Exclusive); try { // By default, connections are auto-commit connection.AutoCommit = true; // Set the default schema for this connection if it exists if (connection.SchemaExists(defaultSchema)) { connection.SetDefaultSchema(defaultSchema); } else { Logger.WarningFormat(this, "Couldn't change to '{0}' schema.", defaultSchema); // If we can't change to the schema then change to the APP schema connection.SetDefaultSchema(ConfigDefaultValues.DefaultSchema); } } finally { try { connection.Commit(); } catch (TransactionException e) { // Just issue a warning... Logger.Warning(this, e); } finally { // Guarentee that we unluck from EXCLUSIVE locker.FinishMode(LockingMode.Exclusive); } } return(new AuthenticatedSession(user, connection)); }
public void CommitTransaction() => Connection.Commit();