Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 638233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:42:37+00:00 2026-05-13T20:42:37+00:00

How can I implement a SqlDataReader inside another SqlDataReader ? My problem is I

  • 0

How can I implement a SqlDataReader inside another SqlDataReader?

My problem is I have a SqlDataReader. I am issuing while (reader.read()) and inside the while loop I have to create another SqlDataReader to read from the database. But I’m getting exceptions about connection being already open.

So what’s the best way to solve my problem?

Edit:

I am using clr to create my stored procedures. I tried to put MultipleActiveResultSets=true; within the connection string of both the clr and the project, and an exception occurred when I
tested my stored procedure on SQL Server:

System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:42:37+00:00Added an answer on May 13, 2026 at 8:42 pm

    You need to have two nested data readers, and this requires the ADO.NET “MARS” feature – Multiple Active Result Sets.

    This is available as of ADO.NET 2.0, and requires a specific setting (MultipleActiveResultSets=true;) in the connection string:

    Server=.\SQLEXPRESS;Database=master;Integrated Security=SSPI;
      MultipleActiveResultSets=true;
    

    See this blog post for an excellent discussion.

    Once you have this, you should be able to have more than one SqlDataReader shared on the same SqlConnection in your code, and use them independently of one another.

    UPDATE: this blog post here mentions that the MARS feature is not available inside the SQL CLR environment 🙁 So that won’t work inside a SQL CLR stored proc….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i can implement the QSB on my app using onSearchRequested() method.i have 4 column
Is there any way I can implement functionality which will clear all my data/files/shared_preferences/database
I have multiple interfaces that my objects can implement. I am wondering if there
I am thinking of how I can implement std::vector from the ground up. How
Anyone have any idea how I can implement this? I'd like to have a
I have a simple problem. I want to decorate the SqlDataReader class so that
I wonder if we can implement and fetch data from different datasources into a
I want to know how I can implement membership provider class to have ability
Can anyone tell how I can implement a Oauth api for my site.I have
How we can implement reply to reply features in Sharepoint discussion Board. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.