Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my application is in windows form(c#) which needs multiple insertion(say 500 times in one go) in sql server 2008 database.I am destroying the command objects, connection objects. It works fine for some occurrences but than it hangs. what more can be done to make it more effective.
if a pause is taken between than its ok but if continuously done than application hangs.
My app picks Enrollment_No and Card_Id from one table and along with those inserts in second table.
Any suggestion it make it more efficient will be heartly accepted...


clscommon lCommon1 = new clscommon();
lCommon1.SetAdapterObject("select Enrollment_No,Card_Id from Student_Details");
lCommon1.lAdapter.Fill(DsGrid);
lCommon1.DestroyAdapterObject();
lCommon1 = null;


foreach (DataGridViewRow Row in dataGridView1.Rows)
{
if (Row.Cells[0].Value.ToString().Trim() != "")
{
bool Chkinrt = false;
string StuCardId = "";
for (int dsC = 0; dsC <= DsGrid.Tables[0].Rows.Count; dsC++)
{
if (DsGrid.Tables[0].Rows[dsC]["Enrollment_No"].ToString() == Row.Cells[0].Value.ToString().Trim())
{
StuCardId = DsGrid.Tables[0].Rows[dsC]["Card_Id"].ToString();
Chkinrt = true;
break;
}
}

if (Chkinrt == true)
{
clscommon lCommon3 = new clscommon();
lCommon3.SetCommandObject("insert into EnrollReg(RegId,Enrollment_No,Card_Id) values(@RegId,@Enrollment_No,@Card_Id)");
lCommon3.AddParameterInCommandObject("RegId", RegID);
lCommon3.AddParameterInCommandObject("Enrollment_No", Row.Cells[0].Value.ToString().Trim());
lCommon3.AddParameterInCommandObject("Card_Id", StuCardId);
lCommon3.objCommand.ExecuteNonQuery();
lCommon3.DestroyCommandObject();
lCommon3 = null;
}
}
}

MessageBox.Show("Student's Class Record Added Successfully");
Posted
Comments
[no name] 24-Apr-14 7:28am    
http://www.c-sharpcorner.com/UploadFile/dsdaf/ConnPooling07262006093645AM/ConnPooling.aspx

Connection pooling refers to the task of grouping database connections in cache to make them reusable because opening new connections every time to a database is a time-consuming process. Therefore, connection pooling enables you to reuse already existing and active database connections, whenever required, and increasing the performance of your application. You can enable or disable connection pooling in your application by setting the pooling property to either true or false in connection string. By default, it is enabled in an application.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900