asp.net中网站代码分析中出现的警告,请大家帮忙!!
public class DbObject
{
private string ConnectionString;
private OleDbConnection Conn;
private OleDbCommand Comm;
private OleDbDataReader Reader;
private OleDbDataAdapter Adapter;
private DataSet Ds;
public DbObject()
{
ConnectionString=ConfigurationManager.ConnectionStrings[ "ConnString "].ConnectionString+HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings[ "ConnData "].ConnectionString);
Conn = new OleDbConnection(ConnectionString);
Comm = new OleDbCommand();
Comm.Connection = Conn;
}
/// <summary>
/// 释放连接及内存资源
/// </summary>
protected void Dispose()
{
if (Conn != null)
{
Conn.Close();
Conn.Dispose();
}
if (Comm != null)
{
Comm.Dispose();
}
//if (Ds != null)
//{
// Ds.Dispose();
//}
}
/// <summary>
/// 执行Sql语句,无返回值
/// </summary>
/// <param name= "sql "> sql语句 </param>
protected void ExecuteNonQuery(string sql)
{
Conn.Open();
Comm.CommandText = sql;
Comm.ExecuteNonQuery();
Dispose();
}
警告如下:
1\警告 1 CA1001 : Microsoft.Design : 在“DbObject”上实现 IDisposable,因为它实例化下列 IDisposable 类型的成员: System.Data.OleDb.OleDbCommand, System.Data.OleDb.OleDbConnection e:\site\lirong\App_Code\DbObject.cs 13 e:\site