Why my sql query work with one parameters, but working with another?

0

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?

c#
sql
dapper
asked on Stack Overflow Jun 16, 2020 by user3555620

1 Answer

0

This code solve my problem

new { name = new DbString() { Value = name, Length = 300, IsAnsi = true}}

Only when i set length and ansi

answered on Stack Overflow Jun 16, 2020 by user3555620

User contributions licensed under CC BY-SA 3.0