Dapper QueryMultiple throws "No columns were selected"

发布时间 2023-11-17 14:00:42作者: 不及格的程序员-八神

调试存储过程发现某字段NULL,拼成的SQL最后啥也没有了。。。
原因是存储过程没有执行到查询SQL语句

QueryAsync throws "No columns were selected" when stored proc doesn't perform a select statement #591

Closed
 
 
toannguyen83 opened this issue on Aug 27, 2016 · 18 comments
 
Closed
 
 
 

Comments

@toannguyen83
 
 

Tested on Dapper 1.42 and 1.50.2

The following sql statement will simulate creating a temp stored proc and execute it with dapper

create procedure #TestProcedure
as
begin

    -- basically a failed if statement, so the select is not happening and the stored proc return nothing
    if 1=0
    begin
        select 
            'Password' as ColumnName,
            'Cannot be the same as your username' as [Message]
    end

end

exec #TestProcedure
 

When using Query version, it works fine and no results return. When using QueryAsync version, it throws "No columns were selected" error.

I attached a code sample using microsoft localdb. The sample project is using Dapper 1.50.2 and structure similar to the one I submitted in #501

DapperBugReplication20160827.zip

 
@adamhartford
 
 

I ran into this problem too. I also noticed that it works correctly in Mono, but not .NET.

 
@nickInMN
 
 
nickInMN commented on Jan 13, 2017 • 
edited 

I'm having this same problem. Is there any plan to get this fixed, it is a pretty serious issue. Having to query the database to get the object to update is cumbersome.

 
@andreujuanc
 
 

I can confirm that the issue affects async version of query, but it works fine otherwise.

 
@joaopgrassi
 
 
joaopgrassi commented on Sep 8, 2017 • 
edited 

Nothing on this? This is a real problem.. We have a bunch of procs that throw errors if the sensitive data you queried is not there:

IF @@ROWCOUNT = 0 RAISERROR ('User does not exists', 11, 1)

The database is old, and I'm not going to ask them to change 1000 procs to adjust to my code. multireader should expose some safe reader so we don't get these errors.

@alexbudisan