I’m having a hard time with what appears to be a connection issue. I have scoured the web and sounds like this is not the way to go but if someone has any thoughts or ideas that would be great.
I have a hunch it’s because these 4 pages are using the same .cs code file and all logic is happening OnLoad() so it is kicking the other off? These reports are for display only, no input required from user.
Please let me know if more information is needed, thank you!
Issue:
- Page loads fine on its own but if multiple tabs are ran and one is still processing, it halts this and then displays missing data and formatting. Can sometimes be mimicked by pressing refresh (F5) twice quickly.
Environment:
- IIS running on server
- DB2Database (IBM)
Web Report:
- 4 asp.net pages that link to same Default.CS code file (ex. /dash/steel.aspx, /dash/steelnums.aspx)
- On page load > read CSV files using StreamReader > run SQL query > format/display information into data grid view
Connection Example:
iDB2Connection BlueDB2Connection = new iDB2Connection(strConnectionString);
iDB2DataAdapter BlueDB2PartsDataAdapter = new iDB2DataAdapter();
iDB2Command SqlCmd = BlueDB2Connection.CreateCommand();
SqlCmd.CommandTimeout = 1000000000;
// select proper query based on page being loaded
if (curPage.Contains("amewood"))
{
SqlCmd.CommandText = sqlMainDataWood();
}
else if (curPage.Contains("amesteel"))
{
SqlCmd.CommandText = sqlMainDataSteel();
}
BlueDB2PartsDataAdapter.SelectCommand = SqlCmd;
try
{
BlueDB2PartsDataAdapter.Fill(dsParts);
}
catch (SqlException sqlEx)
{
DisplayError.Text = "Error:" + sqlEx.Message;
}
Reading CSV function:
using (StreamReader reader = new StreamReader(basePath + filePath + "daysStart.csv"))
{
var headerLine = reader.ReadLine();
var line = reader.ReadToEnd();
var values = line.Split(',');
DateTime dt;
DateTime today = DateTime.ParseExact(DateTime.Now.ToString("MMddyyyy"), "MMddyyyy", CultureInfo.InvariantCulture);
int i = 0;
if (values.Length != 0)
{
foreach (string item in values)
{
if (item != "")
{
dt = DateTime.ParseExact(item, "MMddyyyy", CultureInfo.InvariantCulture);
dateData.startDate = dt;
}
else
{
dateData.startDate = today;
}
i++;
}
}
else
{
dateData.startDate = today;
}
}
Troubleshooting:
- Attempted multiple threading
- Tried delays prior to code
- Tested that the CSV’s were not causing the issue
2
Answers
Sorry for the delay, I don't get much time to work on this. The issue turned out to be related to a static variable that was being overwritten... face palm. I'm sure if I posted all of the code you would have noticed it immediately. Thank you for your time and effort.
Not closing the DB connection (disposing it) would be the culprit. After running every command or query, you have to dispose of the connection (or at the end of the event handler function). As @Dai suggested if you’re not limited to using DB2 and Web Forms you should use newer technologies such as ASP.net MVC and EntityFramework or other ORMs.
Update :
after reading your link:
it is maybe from not sharing the same instance of DB2DataAdapter object. Share it with
static
modifier between pages and see if it helps.