{"record":{"id":"d66dc43e1859e378","repo":"JosefNemec/Playnite","slug":"can-t-write-to-databasepath-folder","errorCode":null,"errorMessage":"Can't write to \"{DatabasePath}\" folder.","messagePattern":"Can't write to \"(.+?)\" folder\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"source/Playnite/Database/GameDatabase.cs","lineNumber":514,"sourceCode":"            else\r\n            {\r\n                return path;\r\n            }\r\n        }\r\n\r\n        public void OpenDatabase()\r\n        {\r\n            if (string.IsNullOrEmpty(DatabasePath))\r\n            {\r\n                throw new Exception(\"Database path cannot be empty.\");\r\n            }\r\n\r\n            var dbExists = File.Exists(DatabaseFileSettingsPath);\r\n            logger.Info(\"Opening db \" + DatabasePath);\r\n\r\n            if (!FileSystem.CanWriteToFolder(DatabasePath))\r\n            {\r\n                throw new Exception($\"Can't write to \\\"{DatabasePath}\\\" folder.\");\r\n            }\r\n\r\n            // This fixes an issue where people mess up their library with custom scripts\r\n            // which create collection files instead of directories :|\r\n            if (File.Exists(FilesDirectoryPath))\r\n            {\r\n                File.Delete(FilesDirectoryPath);\r\n            }\r\n\r\n            if (!dbExists)\r\n            {\r\n                FileSystem.CreateDirectory(DatabasePath);\r\n                FileSystem.CreateDirectory(FilesDirectoryPath);\r\n            }\r\n\r\n            if (!dbExists)\r\n            {\r\n                Settings = new DatabaseSettings() { Version = NewFormatVersion };\r","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/JosefNemec/Playnite/blob/5911f4e964e628aa7a69c2030ab35101afa63067/source/Playnite/Database/GameDatabase.cs#L496-L532","documentation":"Thrown as a generic Exception by GameDatabase.OpenDatabase() when FileSystem.CanWriteToFolder(DatabasePath) returns false. The database directory must be writable for Playnite to store game data, files, and settings. Read-only locations (locked folders, protected system directories, read-only network shares) cause this error.","triggerScenarios":"DatabasePath points to a read-only directory, a folder the current user lacks write permissions for, a read-only mounted network share, or a folder locked by another process. CanWriteToFolder attempts a test write and it fails.","commonSituations":"Database is on a read-only network share or USB drive with write protection. The folder is owned by another user or SYSTEM with no write ACL for the current user. Antivirus or ransomware protection blocks writes to the folder. The path is inside Program Files without elevation. Cloud sync (OneDrive/Dropbox) created a read-only placeholder.","solutions":["Move the database to a writable directory (e.g., %AppData%\\Playnite or a local user folder).","Fix folder permissions: right-click the folder > Properties > Security > grant the current user Write permission.","If on a network share, ensure the share is mounted with read-write access.","Disable write-protection on USB/removable media.","If cloud sync is interfering, exclude the database folder or move it outside the sync root."],"exampleFix":"// before — database path on a read-only share\ngameDatabase.DatabasePath = @\"\\\\server\\share\\PlayniteDB\";\ngameDatabase.OpenDatabase(); // throws\n\n// after — use a writable local path\ngameDatabase.DatabasePath = Path.Combine(\n    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),\n    \"Playnite\", \"database\");\ngameDatabase.OpenDatabase();","handlingStrategy":"validation","validationCode":"if (!FileSystem.CanWriteToFolder(gameDatabase.DatabasePath))\n{\n    logger.Error($\"Cannot write to database folder: {gameDatabase.DatabasePath}\");\n    // fall back to default AppData path or prompt user for a new location\n    gameDatabase.DatabasePath = Path.Combine(\n        Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),\n        \"Playnite\", \"database\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a writable local directory for the database (AppData or user home).","Avoid network shares, cloud-sync folders, and read-only media for database storage.","Check folder write permissions during startup and warn the user early."],"tags":["database","permissions","filesystem","configuration","write-access"],"backgroundTag":null,"analyzedSha":"5911f4e964e628aa7a69c2030ab35101afa63067","analyzedAt":"2026-08-13T17:38:25.713Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}