I have a console application that moves data from one database to another. App reads data, updates it and writes into another db. Queries are very simple and they are logged in case of error. So I can try to execute each of them separately and it doesn't take more than 50 ms (Profiler told me that). But I have a lot of rows and after executing some of them (1 000 - 10 000 very different amount of executed rows) I get a time out: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. TimeOut can be got even during "SELECT" query.
I've set CommandTimout to 120 and got A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable) So, I think it's not a timeout case.
Profiler and traces didn't got anything unexpected.
I used SqlConnection.ClearPool(cnnct); but it doesn't work;
Please, help.
SQL Vertion: Microsoft SQL Server 2008 R2 (SP1)
Here is the code for source and destination dbs.
public IEnumerable<SomeType> GetEntities()
{
IEnumerable<SomeType> result = null;
var selectQuery = GetSelectQuery();
try
{
using (var cnnct = new SqlConnection(_connectionString))
{
cnnct.Open();
var cmd = new SqlCommand(selectQuery, cnnct);
var reader = cmd.ExecuteReader();
result = Convert(reader);
reader.Close();
cmd.Dispose();
}
}
catch (Exception e)
{
Catch(selectQuery, e);
}
return result;
}
public Int32 Save(SomeType entity)
{
Int32 result = 0;
var insertQuery = GetInsertQuery(entity);
try
{
using (var cnnct = new SqlConnection(_connectionString))
{
cnnct.Open();
var cmd = new SqlCommand(insertQuery, cnnct);
result = (Int32)(Decimal)cmd.ExecuteScalar();
cmd.Dispose();
}
}
catch (Exception e)
{
Catch(insertQuery, e);
}
return result;
}