Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

SqlDataReader not throwing an exception

$
0
0

I have method 

public static SqlDataReader ExecuteReader(SqlCommand cmd, int level = 0)
{
SqlConnection conn = cmd.Connection;
SqlDataReader dr = null;
cmd.CommandTimeout = SqlConnectionTimeOut;

DateTime start = DateTime.Now;
DateTime end = new DateTime();
try
{
if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}
dr = cmd.ExecuteReader();

}
catch (SqlException sqlex)
{
end = DateTime.Now;
TimeSpan requestDuration = end - start;
LoggerHelper.Info("SqlException - Execute reader duration before exception in miliseconds: " + requestDuration.TotalMilliseconds.ToString());
LoggerHelper.Error("Execute reader ", sqlex ,cmd);

if (sqlex.Number == 1205 && level <= 3) // will try to execute 3 times before throwing an Process deadlocked exception
{
LoggerHelper.Info(cmd.CommandText + " was a victim of deadlock. This was attempt " + (level + 1).ToString());
dr = ExecuteReader(cmd, level++);
}
else
{
throw new Exception("Execute reader ", sqlex);
}
// throw new Exception("Execute reader ", sqlex);
}
catch (Exception ex)
{
end = DateTime.Now;
TimeSpan requestDuration = end - start;
LoggerHelper.Info("Exception - Execute reader duration before exception in miliseconds: " + requestDuration.TotalMilliseconds.ToString());
LoggerHelper.Error("Execute reader ", ex, cmd);
throw new Exception("Execute reader ", ex);
}

return dr;

}

which is called from DAL

SqlDataReader reader = DataBridgeDb.ExecuteReader(TrisuraCommand);
datatable.Load(reader, LoadOption.OverwriteChanges, tablenames);

while debugging sql deadlock exception is properly thrown in ExecuteReader method.

But when i deploy or change connection string to staging database exception is thrown in datatable.Load method.

does anyone knows why? i think it comes to database properties difference or sql server difference? 


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>