private DataTable GetDataTable(string strSql)
{
DataTable dt = new DataTable();
try
{
SqlDataAdapter da = new SqlDataAdapter(strSql,this.conn);
this.conn.Open();
da.Fill(dt);
da.Dispose();
}
catch
{
dt = null;
}
finnally
{
this.conn.close();
}
return dt;
}
{
DataTable dt = new DataTable();
try
{
SqlDataAdapter da = new SqlDataAdapter(strSql,this.conn);
this.conn.Open();
da.Fill(dt);
da.Dispose();
}
catch
{
dt = null;
}
finnally
{
this.conn.close();
}
return dt;
}
应该及时关闭连接的,在连接池中自动保存的
<add key="strConnection" value="server=localhost; uid=sa; pwd=tcwl;database=zzq"></add>
</appSettings>
定义公共数据库连接对象
dim cnn as new sqlconnection(configurationsettings("strConnection"))
保证使用完全相同的数据库连接字符串,可以默认启用缓冲池,SqlDataAdapter可以不显式打开数据库,完成操作后会自动关闭。
自己感觉你写打开数据库的函数没有必要。
this.conn.Dispose();
一般连接用时OPEN它,用完后CLOSE它即可,不能DISPOSE.DISPOSE后要重新NEW的,不能OPEN了.
"Enlist=true;Pooling=true;Max Pool Size=300;Min Pool Size=0;Connection Lifetime=300;user id=sa;packet size=4096";
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=60785
brightheroes(闭关|重剑无锋 大巧不工)的方案是可行的 !
连接代码为什么不放在web.config中呢?