Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / System / Data / Odbc / OdbcEnvironmentHandle.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="OdbcEnvironmentHandle.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9 using System;
10 using System.Collections;
11 using System.ComponentModel;
12 using System.Data;
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;
19 using System.Text;
20 using System.Threading;
21 using System.Runtime.Versioning;
22
23 namespace System.Data.Odbc {
24
25     sealed internal class OdbcEnvironmentHandle : OdbcHandle {
26
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;
32             
33             //Set the expected driver manager version
34             //
35             retcode = UnsafeNativeMethods.SQLSetEnvAttr(
36                 this,
37                 ODBC32.SQL_ATTR.ODBC_VERSION,
38                 ODBC32.SQL_OV_ODBC3,
39                 ODBC32.SQL_IS.INTEGER);
40             // ignore retcode
41
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.
46             //
47             retcode = UnsafeNativeMethods.SQLSetEnvAttr(
48                 this,
49                 ODBC32.SQL_ATTR.CONNECTION_POOLING,
50                 ODBC32.SQL_CP_ONE_PER_HENV,
51                 ODBC32.SQL_IS.INTEGER);
52
53             switch(retcode) {
54             case ODBC32.RetCode.SUCCESS:
55             case ODBC32.RetCode.SUCCESS_WITH_INFO:
56                 break;
57             default:
58                 Dispose();
59                 throw ODBC.CantEnableConnectionpooling(retcode);
60             }
61         }
62     }
63 }
64