Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

If an application is running on a server "ServerA" and the database is on another server "ServerB", and the code is as below :

Method in application

C#
private static void CreateCommand(string queryString,
    string connectionString)
{
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        connection.Open();

        SqlCommand command = new SqlCommand(queryString, connection);
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            if (UseFilePartValidate(reader))
            {
               AddPartsToFile(reader);
            }
        }
    }
}


Method called with queryString parameter set to

SQL
SELECT FileName, FilePart, FileID FROM SomeFileTable ORDER BY FilePartOrder


where will this do it's filtering of the data, ServerA or ServerB? If ServerA does that mean it will pull all the data across to ServerA, as in all the file parts of all the files in that table?

I assume this will bring all the data across to ServerA but lately I've seen with a lot of older projects that it works as in the example above, especially with Collections and just thought maybe I was missing something.

Thanks in advance
Posted
Updated 24-Jan-12 23:41pm
v3

1 solution

Since your command doesn't do any filtering, none of them!

If your command was:
SQL
SELECT FileName, FilePart, FileID FROM SomeFileTable WHERE FileID < 20 ORDER BY FilePartOrder
Then ServerB will do the filtering, since it receives the whole command. That is one of the reasons why you shouldn't say
SQL
SELECT * FROM myTable
instead of specifying the fields you want as in your example. It wastes bandwidth on the transfer as well as memory on the server - this can be significant when your table contains images for example.

This assumes you are using SQL Server, or MySQL: if you are using Access for some strange reason, then all the data has to be pulled to ServerA as the command is executed there so any filtering will be done there.
 
Share this answer
 
v2
Comments
Gordon Beeming 25-Jan-12 11:04am    
The method "UseFilePartValidate" does validation on the data in the reader, sorry I didn't make this clear just thought the name would of made sense
OriginalGriff 25-Jan-12 11:05am    
It is a much, much better idea to do that at the database server - it is optimised for that kind of thing!
Gordon Beeming 25-Jan-12 14:33pm    
Ja, I do all my filtering in the database because that' what SQL is good at but was mainly wondering if I was missing something with a ExecuteReader as most Collections I'm seeing in older projects do it in the Data Access Layer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900