{"record":{"id":"49ea57aa3aa0e2ab","repo":"tursodatabase/turso","slug":"connection-must-be-a-sqliteconnection-49ea57","errorCode":null,"errorMessage":"Connection must be a SqliteConnection.","messagePattern":"Connection must be a SqliteConnection\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteBatch.cs","lineNumber":41,"sourceCode":"        ArgumentNullException.ThrowIfNull(connection);\n        _connection = connection;\n        _transaction = connection.Transaction;\n        _timeout = connection.DefaultTimeout;\n    }\n\n    public new SqliteBatchCommandCollection BatchCommands => _batchCommands;\n\n    protected override DbBatchCommandCollection DbBatchCommands => _batchCommands;\n\n    protected override DbConnection? DbConnection\n    {\n        get => _connection;\n        set\n        {\n            _connection = value as SqliteConnection\n                          ?? (value is null\n                              ? null\n                              : throw new ArgumentException(\n                                  \"Connection must be a SqliteConnection.\",\n                                  nameof(value)));\n            if (_connection is not null)\n                _timeout = _connection.DefaultTimeout;\n        }\n    }\n\n    protected override DbTransaction? DbTransaction\n    {\n        get => _transaction;\n        set => _transaction = value as SqliteTransaction\n                             ?? (value is null\n                                 ? null\n                                 : throw new ArgumentException(\n                                     \"Transaction must be a SqliteTransaction.\",\n                                     nameof(value)));\n    }\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteBatch.cs#L23-L59","documentation":"SqliteBatch.Connection is typed as DbConnection but this facade only works with a Turso SqliteConnection. The setter downcasts the assigned value and throws ArgumentException immediately if the value is a non-null object of any other DbConnection-derived type (e.g. Microsoft.Data.Sqlite.SqliteConnection or a custom provider connection).","triggerScenarios":"Assigning any DbConnection instance that is not bindings/dotnet Turso.Data.Sqlite.SqliteConnection to SqliteBatch.Connection, e.g. batch.Connection = new Microsoft.Data.Sqlite.SqliteConnection(connStr) or a connection from a DI container registered with the wrong type.","commonSituations":"Mixing Microsoft.Data.Sqlite and Turso.Data.Sqlite packages in one project; resolving a connection from a generic DI/factory that returns the base DbConnection type; copy-pasted code from a Microsoft.Data.Sqlite sample.","solutions":["Create the connection with the Turso.Data.Sqlite namespace: new SqliteConnection(connectionString) and import that namespace, not Microsoft.Data.Sqlite","Check using directives and package references: remove Microsoft.Data.Sqlite or fully qualify the Turso type","If the value comes from DI, register/implement the factory so it returns Turso.Data.Sqlite.SqliteConnection"],"exampleFix":"// before\nusing Microsoft.Data.Sqlite;\nbatch.Connection = new SqliteConnection(connString); // ArgumentException\n// after\nusing Turso.Data.Sqlite;\nbatch.Connection = new SqliteConnection(connString);","handlingStrategy":"type-guard","validationCode":"if (value is not Turso.Data.Sqlite.SqliteConnection)\n    throw new ArgumentException($\"Expected Turso SqliteConnection, got {value?.GetType().FullName}\");","typeGuard":"static bool IsTursoSqliteConnection(DbConnection? c) => c is Turso.Data.Sqlite.SqliteConnection;","tryCatchPattern":"try { batch.Connection = conn; }\ncatch (ArgumentException ex) when (ex.ParamName == \"value\") { /* log wrong provider type, fix DI registration */ }","preventionTips":["Fully qualify or alias the Turso connection type when both Microsoft.Data.Sqlite and Turso are referenced","Register the exact Turso.Data.Sqlite.SqliteConnection type in DI, not DbConnection","Check batch.Connection assignment types at compile time by keeping variables strongly typed"],"tags":["csharp","dotnet","argument","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-09-06T07:15:26.990Z","contentChangedAt":"2026-09-06T07:15:26.990Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}