tursodatabase/turso · error · NotSupportedException

TursoBatchCommand only supports CommandType.Text.

Error message

TursoBatchCommand only supports CommandType.Text.

What it means

TursoBatchCommand is the per-statement entry inside a TursoBatch, and the Turso engine only executes raw SQL text. The CommandType setter accepts only CommandType.Text and throws NotSupportedException for StoredProcedure or TableDirect because there is no stored-procedure catalog to invoke. The getter always reports Text.

Source

Thrown at bindings/dotnet/src/Turso.Data/TursoBatchCommand.cs:36

    public TursoBatchCommand(string commandText)
    {
        CommandText = commandText;
    }

    [AllowNull]
    public override string CommandText
    {
        get => _commandText;
        set => _commandText = value ?? "";
    }

    public override CommandType CommandType
    {
        get => _commandType;
        set
        {
            if (value != CommandType.Text)
                throw new NotSupportedException("TursoBatchCommand only supports CommandType.Text.");

            _commandType = value;
        }
    }

    protected override DbParameterCollection DbParameterCollection => _parameters;

    public new TursoParameterCollection Parameters => _parameters;

    public override int RecordsAffected => _recordsAffected;

    public override bool CanCreateParameter => true;

    public override DbParameter CreateParameter()
    {
        return new TursoParameter();
    }

View on GitHub (pinned to 244cde92a7)

Solutions

  1. Remove the CommandType assignment; Text is the default and the getter always returns Text.
  2. Replace the stored-procedure call with the equivalent inline SQL in CommandText (e.g. EXEC or the full statement body).
  3. In provider-agnostic helper code, only assign CommandType when the concrete provider supports values other than Text.

Example fix

// before
var cmd = batch.Commands.Add(new TursoBatchCommand());
cmd.CommandText = "usp_GetUser";
cmd.CommandType = CommandType.StoredProcedure; // throws NotSupportedException

// after
var cmd = batch.Commands.Add(new TursoBatchCommand());
cmd.CommandText = "SELECT * FROM users WHERE id = @id"; // CommandType.Text is the default
Defensive patterns

Strategy: validation

Validate before calling

var desired = CommandType.StoredProcedure;
if (cmd is TursoBatchCommand && desired != CommandType.Text)
{
    // TursoBatchCommand only supports Text; inline the SQL instead of assigning.
    throw new NotSupportedException($"Cannot set {desired} on a TursoBatchCommand; use inline SQL.");
}

Try / catch

try
{
    cmd.CommandType = CommandType.StoredProcedure;
}
catch (NotSupportedException)
{
    // Provider only supports Text: rewrite as inline SQL in CommandText.
}

Prevention

When it happens

Trigger: Assigning batchCommand.CommandType = CommandType.StoredProcedure or CommandType.TableDirect on an item obtained from a TursoBatch.Commands collection (TursoBatchCommand.cs:30-38).

Common situations: Porting Microsoft.Data.SqlClient batch code that calls stored procedures via CommandType.StoredProcedure; generic ADO.NET helpers or ORM interceptors that set CommandType on every DbBatchCommand regardless of provider; DI configuration that assumes SqlClient semantics.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/66a8e06f532e8052. Report an issue: GitHub.