Home > Database > Mysql Tutorial > SqlServer 数据库连接问题? 请高手解答

SqlServer 数据库连接问题? 请高手解答

WBOY
Release: 2016-06-07 15:33:59
Original
1294 people have browsed it

for 循环 完毕后在关数据库连接。这样可以减少资源耗费。Close虽然不会立即关闭,但是从连接池获取连接也是要耗费资源的。sql尽量用参数方式,这样可以减少dbserver cpu的占用率,因为sql不需要重复编译。大概代码如下: using(var con=new Connection()) {

for 循环 完毕后在关数据库连接。这样可以减少资源耗费。Close虽然不会立即关闭,但是从连接池获取连接也是要耗费资源的。sql尽量用参数方式,这样可以减少dbserver cpu的占用率,因为sql不需要重复编译。大概代码如下:

using(var con=new Connection())

{

    var command=//创建Parameter列表和SqlCmmand

     for(int i=0;i

     {

            //把Value值 给 commnad.Parameters

            command.execute()

      }

}

当然还有其他的优化方式,但至少要做到上面那种。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template