处理数据连接比较好的办法
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。 |
处理数据连接是.NET编程的基本之基本,办法很多,有在open前判断是否关闭的,有用reader时加commandbehavior的,有在finally中经判断来释放资源保证关闭连接的,以我的经验而言下面的最为省资源: using (SqlConnection conn = new SqlConnection(connectingString))
{
conn.Open();
try
{
/* do sth.*/
}
catch (***Exception ex)
{
/* handle *** exception */
// Although you really should try limit the catch
// statement to specify ONLY the type of exception
// you are prepared to handle, and NOT catch ALL
// exceptions.
}
} 本文出自 “张大磊” 博客,转载请与作者联系! 本文出自 51CTO.COM技术博客 |



张大磊
博客统计信息
热门文章
最新评论
友情链接