Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Microsoft SQL Server 2005 Developer’s Guide- P22:SQL Server 2005 is a feature-rich release that provides a host of new tools and technologies for the database developer. This book is written to help database developers and DBAs become productive immediately with the new features and capabilities found in SQL Server 2005. | Chapter 6 Developing Database Applications with ADO.NET 189 A string variable containing the server name is passed in to the beginning of this subroutine and then two SqlConnection objects cn and cn2 are created that have identical connection strings. In both cases the ConnectionString property uses the SERVER keyword to identify the SQL Server instance to connect to and the INTEGRATED SECURITY keyword to specify that Windows integrated security will be used. After the two SqlConnection objects have been created a Try-Catch loop is used to open the connection to SQL Server and capture any run-time errors. Since the values of these connection strings are identical they will both be part of the same connection pool. If the connection strings were different in any way then two separate connection pools would have been created. After the connections have been established the Close method is used to close each connection. Pooling Related Connection String Keywords While the .NET Framework Data Provider for SQL Server automatically handles connection pooling for you there are still several connection string keywords that you can use to alter the SQLConnection object s connection pooling behavior. Table 6-2 presents the ConnectionString values you can use to customize the SQL Server .NET Data Provider s connection pooling behavior. Name Description Connection Lifetime After a connection is closed it s returned to the pool. Then its creation time is compared with the current time and the connection is destroyed if the difference exceeds the value specified by Connection Lifetime. A value of 0 specifies that pooled connections will have the maximum lifespan. Connection Reset When True this specifies that the connection is reset when it s removed from the pool. For Microsoft SQL Server version 7.0 you can set this value to False to avoid an additional server round trip after opening a connection. However the previous connection state and database context will not be reset. .