I have to simple query
public async Task<Posting> GetById(long id)
{
await using var cnn = new SqlConnection(_settings.Value.ConnectionString);
await cnn.OpenAsync();
return await cnn.QueryFirstOrDefaultAsync<Posting>(
@"select id from dbo.ArticlePostingLst where id = @id", new { id });
}
and another query
public async Task<Posting> GetByName(string name)
{
await using var cnn = new SqlConnection(_settings.Value.ConnectionString);
await cnn.OpenAsync();
return (await cnn.QueryFirstOrDefaultAsync<Posting>(
@"select id from dbo.ArticlePostingLst where name = @name", new { name }));
}
First query work normal, but second query catch with exception Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
If i replace parameter in query to string like this
select id from dbo.ArticlePostingLst where name = '123';
In this case all work normal, i try logging my problem query, but error query not logging, what is the magic of dapper?
This code solve my problem
new { name = new DbString() { Value = name, Length = 300, IsAnsi = true}}
Only when i set length and ansi
User contributions licensed under CC BY-SA 3.0