ExecuteReader appears to query data twice
Posted: Fri 08 Feb 2019 21:07
We are using Dot Connect for PostGreSQL with PostGreSQL 10.5.
While using ANTS Performance Profiler (v 10.1.3.1233) to track down some performance issues, I noticed that the profiler indicates that some database calls are being performed twice. I cannot see the duplicate database calls directly, but I am confident they are actually occurring twice, and not merely being reported twice, since the elapsed times per duplicate calls, while very close, are not exactly the same.
Below is a sample console app that demonstrates performing a simple select statement two different ways.
When run through ANTS Performance Profiler, its "Database calls" tab shows that the select statement was run 3 times: Once from LoadATable and twice from LoadBTable. Note that LoadATable uses a PgSqlDataAdapter and its Fill method, while LoadBTable uses PgSqlCommand and its ExecuteReader method.
Can you tell me if my use of the ExecuteReader method has an error that causes PostGreSQL to read the data twice?
Or is this a bug in Dot Connect for PostGreSQL?
Thanks for your assistance.
Bill.
While using ANTS Performance Profiler (v 10.1.3.1233) to track down some performance issues, I noticed that the profiler indicates that some database calls are being performed twice. I cannot see the duplicate database calls directly, but I am confident they are actually occurring twice, and not merely being reported twice, since the elapsed times per duplicate calls, while very close, are not exactly the same.
Below is a sample console app that demonstrates performing a simple select statement two different ways.
Code: Select all
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Devart.Data.PostgreSql;
namespace CGMUSLAB_13142
{
class Program
{
static void Main(string[] args)
{
string pw = Console.ReadLine();
string connectionString = $@"User Id=exp_load_191;Password={pw};Host=D-LAB-TESTSVR2.CGMUS.LOCAL;Port=5432;Database=cgmlab;Unicode=True;Connection Timeout=0;Pooling=True;Max Pool Size=100";
var connection = new PgSqlConnection(connectionString);
connection.Open();
string sql = "select * from organization_detail";
using (var table1 = new DataTable())
{
LoadATable(connection, sql, table1);
}
using (var table2 = new DataTable())
{
LoadBTable(connection, sql, table2);
}
}
private static void LoadATable(PgSqlConnection connection, string sql, DataTable dataTable)
{
using (var dataAdapter = new PgSqlDataAdapter(sql, connection))
{
dataAdapter.Fill(dataTable);
}
}
private static void LoadBTable(PgSqlConnection connection, string sql, DataTable dataTable)
{
using (var command = new PgSqlCommand(sql, connection))
{
using (var olReader = command.ExecuteReader())
{
dataTable.Load(olReader);
}
}
}
}
}
Can you tell me if my use of the ExecuteReader method has an error that causes PostGreSQL to read the data twice?
Or is this a bug in Dot Connect for PostGreSQL?
Thanks for your assistance.
Bill.