We have a ASP.Net web application that connects to its business layer using WCF. Sometimes, I am getting exception when it is performing a huge operation. The interesting part is when I ran it for the first time it was successful. Afterwards it is throwing exception.
Exception: The socket connection was aborted.
The operation is that it uploads zipcodes into database tables from a csv file. First we read from csv file and make a single lengthy string of zipcodes. This is passed to the stored procedure and the database operations are performed.
Note 1:) When I placed breakpoint and tested, it is clear that the creation of the string (after taking data from csv and appending) is pretty fast (less than one minute).
Note 2:) I removed the transaction (from C# code) and tested, even then the exception is there.
Note 3:) There are one lakh (one hundred thousand) records in csv. Each row has four columns (ZipCode, City, County, State). Size of the csv file is 3MB.
I had a doubt about the transaction log size. Then I shrinked the log file using the following command. DBCC SHRINKFILE('MyDB_log', 1) GO
Then I checked the log size using SELECT [Size],Max_Size,Data_Space_Id,[File_Id],Type_Desc,[Name] FROM FRAMIS_R2075.sys.database_files WHERE data_space_id = 0
The Size is 128; Max Size is 268435456; Type_Desc = “LOG”
Even after shrinking the exception is still coming.
Framework: .Net 3.0
DB: SQL Server 2005
Well, it seems like there is an excpetion in the business layer too, when I waited for 20 more minutes. It said, “Invalid Attempt to call Read when the reader is called”. By seeing this, I removed the DbDataReader and used SqlCommand to update the database tables. Again, there came an exception in business layer, after some 20 minutes saying “Timeout exception”. Any idea why this is happening?
private void ProcessDatabaseOperationsForZipCode(StringBuilder dataStringToProcess, int UserID)
{
int CountOfUnchangedZipCode = 0;
string strRetiredZipCode = "";
string strNewZipCode = "";
dataStringToProcess.Remove(dataStringToProcess.Length - 1, 1);
if (dataStringToProcess.Length > 0)
{
//TimeSpan.FromMinutes(0) - to make transaction scope as infinite.
using (TransactionScope transaction = TransactionScopeFactory.GetTransactionScope(TimeSpan.FromMinutes(0)))
{
SqlConnection mySqlConnection = new SqlConnection("data source=myServer;initial catalog=myDB; Integrated Security=SSPI;");
SqlCommand mySqlCommand = new SqlCommand("aspInsertUSAZipCode", mySqlConnection);
mySqlCommand.CommandType = CommandType.StoredProcedure;
mySqlCommand.Parameters.Add("@DataRows",dataStringToProcess.ToString());
mySqlCommand.Parameters.Add("@currDate", DateTime.Now);
mySqlCommand.Parameters.Add("@userID", UserID);
mySqlCommand.Parameters.Add("@CountOfUnchangedZipCode", 1000);
mySqlCommand.CommandTimeout = 0;
mySqlConnection.Open();
int numberOfRows = mySqlCommand.ExecuteNonQuery();
//Database db = DatabaseFactory.CreateDatabase();
//DbCommand cmd = db.GetStoredProcCommand("aspInsertUSAZipCode");
//cmd.CommandTimeout = 0;
//db.AddInParameter(cmd, "@DataRows", DbType.String, dataStringToProcess.ToString());
//db.AddInParameter(cmd, "currDate", DbType.DateTime, DateTime.Now);
//db.AddInParameter(cmd, "userID", DbType.Int32, UserID);
//db.AddOutParameter(cmd, "CountOfUnchangedZipCode", DbType.String, 1000);
//using (DbDataReader rdrUpgradeTypes = (DbDataReader)db.ExecuteReader(cmd))
//{
// //while (rdrUpgradeTypes.Read())
// //{
// // if (!String.IsNullOrEmpty(Utility.GetString(rdrUpgradeTypes, "NewZipCode")))
// // {
// // strNewZipCode = strNewZipCode + "," + Utility.GetString(rdrUpgradeTypes, "NewZipCode");
// // }
// //}
//}
transaction.Complete();
}
}
}