question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SqlDataReader.GetFieldValue{,Async}() should work for Stream and TextReader

See original GitHub issue

Following #30958, where @Wraith2 added the ability to retrieve an XmlReader via SqlDataReader.GetFieldValue() and its async counterpart, we should do the same for Stream and TextReader. These can already be retrieved via GetStream() and GetTextReader() respectively.

The main motivation behind this would be to allow getting Reader/TextReader asynchronously without introducing new GetReaderAsync() and GetTextReaderAsync() methods. See https://github.com/dotnet/corefx/issues/35012#issuecomment-484440830 and below for previous discussion.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Wraith2commented, Mar 31, 2021

@roji i’ve got this working on netcore but because of the different netcore and netfx codebases it’s more difficult to get it working on netfx. Since this would primarily be useful from EF and as far as a know modern EF only works on core or net5 onwards is there a need to implement on netfx immediately? It will eventually be implemented through the merging of the codebases.

1reaction
Wraith2commented, Apr 19, 2019

@bgrainger has pointed out in one of the linked issues elsewhere that there is some slightly unexpected (but deliberate) behaviour when using the current sync stream methods, GetStream, GetTextReader and GetXmlReader all handle database NULL values by detecting it and returning an empty stream. Other methods of accessing the same fields will detect null and throw an appropriate exception.

Should GetFieldValue(Async)<T> for stream types emulate the current behaviour of returning a constructed empty stream or should they throw null as GetString or GetBytes would do?

I think it is up to the developer to ensure that their queries return sensible data and that if null can be present in the return from a query it should be explicitly handled by the consumer and not hidden by the ADO library. I’m in favour of throwing an exception if a stream over null data is requested through GetFieldValue(Async)

Read more comments on GitHub >

github_iconTop Results From Across the Web

SqlDataReader.GetFieldValueAsync<T>(Int32, ...
Asynchronously gets the value of the specified column as a type. GetFieldValue<T>(Int32) is the synchronous version of this method.
Read more >
Access TextReader as a Stream
You can obtain a Stream through the use of the StreamReader class. StreamReader is a subclass of TextReader so you can easily access...
Read more >
Introducing .NET 4.5
For detailed information about how to locate your book's source code, go to www.apress.com/source- code. Page 4. For Belinda and Mum, a book...
Read more >
C# And dotNET Core 1.0 - StudyLib
In particular, you will learn how to declare and work with variables of different types. Chapter 3, Controlling the Flow, Converting Types, and...
Read more >
ADO.NET Retrieving and Modifying Data - Sideway
Open() method passes the parsed connection parameters to the data source. ... in the SqlDataReader classes in order to get Stream, XmlReader, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found