Elastic Queries with Dapper: Procedure expects parameter of type 'ntext/nchar/nvarchar'

402 views Asked by At

I am trying to query a set of Azure SQL Databases using the sp_execute_remote SQL function with Dapper and DynamicParameters as follows:

Task<List<T>> ExecuteMultiShardCommand<T>(SqlBuilder.Template Template, int Timeout = 120) 
{
    var mParams = new DynamicParameters(Template.Parameters);
    mParams.Add("@datasourcename", "<datasource>");
    mParams.Add("@statement", Template.RawSql, DbType.String);

    using (var conn = new SqlConnection(config["<sqlconnectionstring>"])) 
    {
        var results = await conn.QueryAsync<T>("sp_execute_remote", mParams, commandTimeout: Timeout, commandType: CommandType.StoredProcedure);

        return results.ToList();
    }
}

Running this throws a SQL exception:

System.Data.SqlClient.SqlException : Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.

I have not configured Dapper anywhere in my application. Isn't the default handling for DbType.String a nvarchar?

0

There are 0 answers