protected override bool TryOpenDatabase( Solution solution, string workingFolderPath, string databaseFilePath, out IPersistentStorage storage) { // try to get db ownership lock. if someone else already has the lock. it will throw var dbOwnershipLock = TryGetDatabaseOwnership(databaseFilePath); if (dbOwnershipLock == null) { storage = null; return(false); } SQLitePersistentStorage sqlStorage = null; try { sqlStorage = new SQLitePersistentStorage( workingFolderPath, solution.FilePath, databaseFilePath, dbOwnershipLock, _faultInjectorOpt); sqlStorage.Initialize(solution); } catch (Exception) { sqlStorage?.Dispose(); throw; } storage = sqlStorage; return(true); }
protected override bool TryOpenDatabase( Solution solution, string workingFolderPath, string databaseFilePath, out IChecksummedPersistentStorage storage) { if (!TryInitializeLibraries()) { // SQLite is not supported on the current platform storage = null; return(false); } // try to get db ownership lock. if someone else already has the lock. it will throw var dbOwnershipLock = TryGetDatabaseOwnership(databaseFilePath); if (dbOwnershipLock == null) { storage = null; return(false); } SQLitePersistentStorage sqlStorage = null; try { sqlStorage = new SQLitePersistentStorage( workingFolderPath, solution.FilePath, databaseFilePath, dbOwnershipLock, _faultInjectorOpt); sqlStorage.Initialize(solution); } catch (Exception) { if (sqlStorage != null) { // Dispose of the storage, releasing the ownership lock. sqlStorage.Dispose(); } else { // The storage was not created so nothing owns the lock. // Dispose the lock to allow reuse. dbOwnershipLock.Dispose(); } throw; } storage = sqlStorage; return(true); }