{"record":{"id":"04dcccdd917d3e1b","repo":"tursodatabase/turso","slug":"auth-token-requires-a-remote-turso-url-data-source","errorCode":null,"errorMessage":"Auth Token requires a remote Turso URL Data Source.","messagePattern":"Auth Token requires a remote Turso URL Data Source\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoConnection.cs","lineNumber":337,"sourceCode":"\n    private void OpenRemote()\n    {\n        if (_connectionOptions.IsReplica)\n            throw new NotSupportedException(\"Embedded replica connections are not supported yet by the .NET provider. Use a remote URL without Replica Path for direct remote execution.\");\n\n        if (_connectionOptions.SyncInterval > 0)\n            throw new NotSupportedException(\"Sync Interval requires embedded replica support, which is not supported yet by the .NET provider.\");\n\n        if (_connectionOptions.GetEncryptionCipher().HasValue || !string.IsNullOrWhiteSpace(_connectionOptions[\"Encryption Key\"]))\n            throw new InvalidOperationException(\"Encryption Cipher and Encryption Key are local database options and cannot be used with remote Turso URLs.\");\n\n        _remoteClient = new TursoRemoteClient(_connectionOptions.GetRemoteUri(), _connectionOptions.AuthToken);\n    }\n\n    private void ValidateLocalOnlyOptions()\n    {\n        if (!string.IsNullOrWhiteSpace(_connectionOptions.AuthToken))\n            throw new InvalidOperationException(\"Auth Token requires a remote Turso URL Data Source.\");\n        if (!string.IsNullOrWhiteSpace(_connectionOptions.ReplicaPath))\n            throw new InvalidOperationException(\"Replica Path requires a remote Turso URL Data Source.\");\n        if (_connectionOptions.SyncInterval > 0)\n            throw new InvalidOperationException(\"Sync Interval requires a remote embedded replica connection.\");\n        if (_connectionOptions.Tls.HasValue)\n            throw new InvalidOperationException(\"Tls requires a remote Turso URL Data Source.\");\n    }\n\n    private void CloseRemote()\n    {\n        var remoteClient = _remoteClient;\n        if (remoteClient is null)\n            return;\n\n        Exception? closeError = null;\n        try\n        {\n            if (_remoteTransactionActive)","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data/TursoConnection.cs#L319-L355","documentation":"Before opening a local (non-URL) database, Open() runs ValidateLocalOnlyOptions, which rejects keywords that only make sense remotely. The first check throws 'Auth Token requires a remote Turso URL Data Source.' when a non-whitespace Auth Token is present: tokens authenticate to a Turso server, so pairing one with a file path is contradictory.","triggerScenarios":"Open() with 'Data Source=app.db;Auth Token=eyJ...' — a local file plus a token; a token injected as a default into every connection string by configuration or a secrets layer; switching a Data Source from a URL to a local file without removing the token.","commonSituations":"Local development inheriting cloud credentials from shared config; TURSO_AUTH_TOKEN-style env defaults applied uniformly; copy-paste from cloud connection examples.","solutions":["Remove 'Auth Token' for local file databases","Or switch Data Source to a remote URL (libsql:// or https://) where the token is required and used","Keep local and remote connection strings in separate config files (appsettings.Local.json vs appsettings.json)"],"exampleFix":"// before\nvar cs = \"Data Source=app.db;Auth Token=eyJhbGci...\"; // local file + token\n\n// after (local)\nvar cs = \"Data Source=app.db\";\n// after (remote)\nvar cs = \"Data Source=libsql://db.turso.io;Auth Token=eyJhbGci...\";","handlingStrategy":"validation","validationCode":"var opts = TursoConnectionOptions.Parse(cs);\nif (!opts.IsRemote && !string.IsNullOrWhiteSpace(opts.AuthToken))\n    throw new InvalidOperationException(\n        \"Remove 'Auth Token' or switch Data Source to a libsql/https URL.\");","typeGuard":"static bool AuthTokenMatchesMode(string cs)\n{\n    var opts = TursoConnectionOptions.Parse(cs);\n    return opts.IsRemote || string.IsNullOrWhiteSpace(opts.AuthToken);\n}","tryCatchPattern":"try { conn.Open(); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Auth Token requires a remote Turso URL Data Source.\")\n{\n    // drop the token for local dev, or point Data Source at the remote URL\n}","preventionTips":["Separate local and remote connection strings in different config files","Do not blanket-inject auth tokens into every database connection string","Strip mode-specific keywords whenever Data Source changes mode"],"tags":["csharp","dotnet","turso","connection-string","auth","configuration"],"backgroundTag":"invalid-connection-string-option","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}