Archive for SQL Server

You are browsing the archives of SQL Server.

SqlCommand.Cancel before SqlDataReader.Close

I’ve just read that you can improve the performance of your SQL queries to Microsoft SQL Servers using .NET 2.0 by simply cancelling the command before closing your data reader.
using (SqlCommand command = connection.CreateCommand())
{
// Your code here
using (SqlDataReader reader = command.ExecuteReader())
{
// Your code here
command.Cancel();
reader.Close();
}
command.Close();
command.Dispose();
}
This is useful if you do not need the return values sending [...]