Bug 41183 - "System.InvalidOperationException: No data available" when using BeginExecuteReader/EndExecuteReader
Summary: "System.InvalidOperationException: No data available" when using BeginExecute...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-19 16:00 UTC by Andre Raabe
Modified: 2017-09-01 09:30 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro code (2.31 KB, text/plain)
2016-05-19 16:00 UTC, Andre Raabe
Details

Description Andre Raabe 2016-05-19 16:00:36 UTC
Created attachment 16037 [details]
Repro code

Mono Version (Using Docker with "FROM mono"):

Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

SQL Server version:

Microsoft SQL Server 2014 (SP1-CU5) (KB3130926) - 12.0.4439.1 (X64) 
	Feb 15 2016 12:12:43 
	Copyright (c) Microsoft Corporation
	Developer Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

Expected result:

2 times the output of "--> Hello"

Repro:

- Create a simple test database at SQL Server
- Create stored procedure with out variables:

-----8<------
create procedure MonoTest (@InParameter varchar(5), @OutParameter varchar(5) output)
as begin
    -- Simple example by setting out to the same value of in
    select @OutParameter = @InParameter
end

go
-----8<------

- Use and compile sample script from attachment (SqlClientWithExecAndOutVar.cs)
  mcs -r:System.Data SqlClientWithExecAndOutVar.cs

- Run exe with connectionstring as parameter (for mono don't forget to add "Asynchronous Processing = true")
  mono SqlClientWithExecAndOutVar.exe "User ID=<SQL-User>;initial Catalog=<DB-Name>;Data Source=<DB-Server>;Password=<SQL-User-Password>;Asynchronous Processing = true"


Output from windows:

Using ExecuteScalarAsync
--> Hello
Using BeginExecuteReader .. EndExecuteReader
--> Hello

Output from mono:

Using ExecuteScalarAsync
--> Hello
Using BeginExecuteReader .. EndExecuteReader
Error 1
System.InvalidOperationException: No data available.
  at System.Data.SqlClient.SqlDataReader.EnsureDataAvailable () <0x406bf480 + 0x0005f> in <filename unknown>:0
  at System.Data.SqlClient.SqlDataReader.GetValue (Int32 i) <0x406bf310 + 0x0002f> in <filename unknown>:0
  at SqlClientWithExecAndOutVar.Program.Main (System.String[] args) <0x4066fd80 + 0x003e3> in <filename unknown>:0
Comment 1 jerrycheese 2016-10-09 22:42:13 UTC
Also happens to me,

SqlDataReader.HasRows returns true
SqlDataReader.FieldCount returns greater than 1
And i know for a fact that the first column in my table is an Int64 (and that there are entries in that table)

yet SqlDataReader.GetInt64(0) returns a:
System.InvalidOperationException: No data available.

Is anyone aware of a work around for easily reading multiple result sets and their data ?

Note You need to log in before you can comment on or make changes to this bug.