-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathDriverConnectionProvider.cs
51 lines (47 loc) · 1.3 KB
/
DriverConnectionProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Data.Common;
namespace NHibernate.Connection
{
/// <summary>
/// A ConnectionProvider that uses an IDriver to create connections.
/// </summary>
public partial class DriverConnectionProvider : ConnectionProvider
{
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(DriverConnectionProvider));
/// <summary>
/// Closes and Disposes of the <see cref="DbConnection"/>.
/// </summary>
/// <param name="conn">The <see cref="DbConnection"/> to clean up.</param>
public override void CloseConnection(DbConnection conn)
{
base.CloseConnection(conn);
conn.Dispose();
}
/// <summary>
/// Gets a new open <see cref="DbConnection"/> through
/// the <see cref="NHibernate.Driver.IDriver"/>.
/// </summary>
/// <returns>
/// An Open <see cref="DbConnection"/>.
/// </returns>
/// <exception cref="Exception">
/// If there is any problem creating or opening the <see cref="DbConnection"/>.
/// </exception>
public override DbConnection GetConnection(string connectionString)
{
log.Debug("Obtaining DbConnection from Driver");
var conn = Driver.CreateConnection();
try
{
conn.ConnectionString = connectionString;
conn.Open();
}
catch (Exception)
{
conn.Dispose();
throw;
}
return conn;
}
}
}