Click here to Skip to main content
15,895,656 members
Home / Discussions / Database
   

Database

 
GeneralRe: DB Conversion Advice Pin
Jörgen Andersson25-Feb-15 21:08
professionalJörgen Andersson25-Feb-15 21:08 
GeneralRe: DB Conversion Advice Pin
manchanx25-Feb-15 21:33
professionalmanchanx25-Feb-15 21:33 
QuestionService Broker Pin
Member 1116162519-Feb-15 17:15
Member 1116162519-Feb-15 17:15 
AnswerRe: Service Broker Pin
Richard MacCutchan19-Feb-15 21:32
mveRichard MacCutchan19-Feb-15 21:32 
QuestionThe following stored proc is not working Pin
indian14318-Feb-15 16:18
indian14318-Feb-15 16:18 
GeneralRe: The following stored proc is not working Pin
PIEBALDconsult18-Feb-15 16:21
mvePIEBALDconsult18-Feb-15 16:21 
GeneralRe: The following stored proc is not working Pin
indian14319-Feb-15 6:26
indian14319-Feb-15 6:26 
AnswerRe: The following stored proc is not working Pin
Wendelius18-Feb-15 17:28
mentorWendelius18-Feb-15 17:28 
GeneralRe: The following stored proc is not working Pin
indian14319-Feb-15 6:32
indian14319-Feb-15 6:32 
GeneralRe: The following stored proc is not working Pin
Wendelius19-Feb-15 6:57
mentorWendelius19-Feb-15 6:57 
AnswerRe: The following stored proc is not working Pin
Mycroft Holmes18-Feb-15 23:54
professionalMycroft Holmes18-Feb-15 23:54 
AnswerRe: The following stored proc is not working Pin
Eddy Vluggen19-Feb-15 5:31
professionalEddy Vluggen19-Feb-15 5:31 
GeneralRe: The following stored proc is not working Pin
indian14319-Feb-15 6:26
indian14319-Feb-15 6:26 
QuestionMultiple Queries in one Stored procedure Pin
sudevsu18-Feb-15 3:42
sudevsu18-Feb-15 3:42 
AnswerRe: Multiple Queries in one Stored procedure Pin
PIEBALDconsult18-Feb-15 4:00
mvePIEBALDconsult18-Feb-15 4:00 
GeneralRe: Multiple Queries in one Stored procedure Pin
sudevsu18-Feb-15 4:08
sudevsu18-Feb-15 4:08 
GeneralRe: Multiple Queries in one Stored procedure Pin
sudevsu18-Feb-15 4:10
sudevsu18-Feb-15 4:10 
GeneralRe: Multiple Queries in one Stored procedure Pin
Corporal Agarn18-Feb-15 4:33
professionalCorporal Agarn18-Feb-15 4:33 
AnswerRe: Multiple Queries in one Stored procedure Pin
Wendelius18-Feb-15 4:37
mentorWendelius18-Feb-15 4:37 
GeneralRe: Multiple Queries in one Stored procedure Pin
sudevsu18-Feb-15 5:11
sudevsu18-Feb-15 5:11 
GeneralRe: Multiple Queries in one Stored procedure Pin
Wendelius18-Feb-15 6:41
mentorWendelius18-Feb-15 6:41 
SuggestionRe: Multiple Queries in one Stored procedure Pin
Richard Deeming18-Feb-15 5:43
mveRichard Deeming18-Feb-15 5:43 
You don't need to enable MARS to fetch multiple result-sets from a single query; you just load each result-set sequentially. A SqlDataAdapter will take care of that for you, or you can call IDataReader.NextResult in a loop, loading each result-set as you go.

You only need MARS if you're going to have multiple active data-readers open on the same connection at the same time.

In other words:
C#
// This needs MARS:
using (var connection = new SqlConnection("..."))
using (var outerCommand = new SqlCommand("...", connection))
{
    connection.Open();
    using (IDataReader outerReader = outerCommand.ExecuteReader())
    {
        while (outerReader.Read())
        {
            using (var innerCommand = new SqlCommand("...", connection))
            {
                using (IDataReader innerReader = innerCommand.ExecuteReader())
                {
                    while (innerReader.Read())
                    {
                        ...
                    }
                }
            }
        }
    }
}

// This doesn't:
using (var connection = new SqlConnection("..."))
using (var command = new SqlCommand("SELECT ...; SELECT ...; SELECT ...;", connection))
{
    connection.Open();
    using (IDataReader reader = command.ExecuteReader())
    {
        do
        {
            while (reader.Read())
            {
                ...
            }
        } 
        while (reader.NextResult())
    }
}

// Neither does this:
var dataSet = new DataSet();

using (var connection = new SqlConnection("..."))
using (var command = new SqlCommand("SELECT ...; SELECT ...; SELECT ...;", connection))
{
    var adapter = new SqlDataAdapter(command);
    adapter.Fill(dataSet);
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Multiple Queries in one Stored procedure Pin
sudevsu18-Feb-15 6:21
sudevsu18-Feb-15 6:21 
GeneralRe: Multiple Queries in one Stored procedure Pin
Wendelius18-Feb-15 6:42
mentorWendelius18-Feb-15 6:42 
AnswerRe: Multiple Queries in one Stored procedure Pin
Smart00324-Feb-15 23:18
professionalSmart00324-Feb-15 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.