fix:专检
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace WebAPI.Helpers
|
||||
{
|
||||
public class DatabaseHelper : IDisposable
|
||||
{
|
||||
private SqlConnection _sqlConnection;
|
||||
private bool _disposed = false;
|
||||
|
||||
public DatabaseHelper(string connectionString)
|
||||
{
|
||||
_sqlConnection = new SqlConnection(connectionString);
|
||||
_sqlConnection.Open();
|
||||
}
|
||||
|
||||
public SqlConnection GetConnection()
|
||||
{
|
||||
return _sqlConnection;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// 释放托管资源
|
||||
if (_sqlConnection != null)
|
||||
{
|
||||
_sqlConnection.Close();
|
||||
_sqlConnection.Dispose();
|
||||
_sqlConnection = null;
|
||||
}
|
||||
}
|
||||
// 释放非托管资源
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user