1 //------------------------------------------------------------------------------
2 // <copyright file="OdbcEnvironmentHandle.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
10 using System.Collections;
11 using System.ComponentModel;
13 using System.Data.Common;
14 using System.Diagnostics;
15 using System.Globalization;
16 using System.Runtime.InteropServices;
17 using System.Security;
18 using System.Security.Permissions;
20 using System.Threading;
21 using System.Runtime.Versioning;
23 namespace System.Data.Odbc {
25 sealed internal class OdbcEnvironmentHandle : OdbcHandle {
27 // SxS: this method uses SQLSetEnvAttr to setup ODBC environment handle settings. Environment handle is safe in SxS.
28 [ResourceExposure(ResourceScope.None)]
29 [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
30 internal OdbcEnvironmentHandle() : base(ODBC32.SQL_HANDLE.ENV, null) {
31 ODBC32.RetCode retcode;
33 //Set the expected driver manager version
35 retcode = UnsafeNativeMethods.SQLSetEnvAttr(
37 ODBC32.SQL_ATTR.ODBC_VERSION,
39 ODBC32.SQL_IS.INTEGER);
42 //Turn on connection pooling
43 //Note: the env handle controls pooling. Only those connections created under that
44 //handle are pooled. So we have to keep it alive and not create a new environment
45 //for every connection.
47 retcode = UnsafeNativeMethods.SQLSetEnvAttr(
49 ODBC32.SQL_ATTR.CONNECTION_POOLING,
50 ODBC32.SQL_CP_ONE_PER_HENV,
51 ODBC32.SQL_IS.INTEGER);
54 case ODBC32.RetCode.SUCCESS:
55 case ODBC32.RetCode.SUCCESS_WITH_INFO:
59 throw ODBC.CantEnableConnectionpooling(retcode);