如何使连接池更有效? [英] How Connection pooling can be made more effective ?

查看:80
本文介绍了如何使连接池更有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是windows格式(c#),它需要在sql server 2008数据库中多次插入(比如一次500次)。我正在销毁命令对象,连接对象。它适用于某些事件,但它挂起。还有什么可以使它更有效。

如果暂停时间超过了ok,但是如果连续完成而不是应用程序挂起。

我的应用程序从一个表中选择Enrollment_No和Card_Id以及第二个表中的那些插入。

任何能让它更高效的建议都会受到热烈接受......





clscommon lCommon1 =新的clscommon();

lCommon1.SetAdapterObject(选择Enrollment_No,来自Student_Details的Card_Id);

lCommon1.lAdapter.Fill(DsGrid);

lCommon1.DestroyAdapterObject();

lCommon1 = null;





foreach(dataGridViewRow dataGridView1中的行.ROW)

{

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;

休息;

}

}



if(Chkinrt == true)

{

clscommon lCommon3 = new clscommon();

lCommon3.SetCommandObject( 插入EnrollReg(RegId,Enrollment_No,Card_Id)值s(@ 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(成功添加学生班级成绩);

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");

推荐答案

连接池是指对数据库c进行分组的任务缓存中的onnections使它们可重用,因为每次打开数据库的新连接都是一个耗时的过程。因此,连接池使您可以在需要时重用已存在的和活动的数据库连接,并提高应用程序的性能。您可以通过在连接字符串中将pooling属性设置为true或false来启用或禁用应用程序中的连接池。默认情况下,它在应用程序中启用。
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.


参考



http://www.c-sharpcorner.com/UploadFile/dsdaf/ConnPooling07262006093645AM/ConnPooling.aspx [ ^ ]



http://msdn.microsoft.com/en-us/ library / 8xx3tyca(v = vs.110).aspx [ ^ ]


这篇关于如何使连接池更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆