0

嗨,我在以下环境中托管了 Web 应用程序。单核,1 GB RAM,40 GB 硬盘,700 GB 带宽。目前有 4-6 个用户正在研究它。有一个表单管理策略,其中所有策略都显示在网格视图中。为此,我从静态方法返回一个数据表。我的结构如下,

private void BindGrid(object sortExp) // Method to bind Grid
{

    DataTable dt = PolicyAccess.GetAllPolicy(some parameters for filter);
    GRV1.DataSource = dt; 
    GRV1.DataBind();
    dt.Dispose();

}

我在非静态类中有以下静态方法,它返回数据表

public static DataTable GetAllPolicy(string pmPolicyNo, int type)
{
    // get a configured DbCommand object
    DbCommand comm = GenericDataAccess.CreateCommand();
    // set the stored procedure name
    comm.CommandText = "proc_docGetAllPolicy";

    // create a new parameter
    DbParameter param = comm.CreateParameter();
    param.ParameterName = "@pmPolicyNo";
    param.Value = pmPolicyNo;
    param.DbType = DbType.String;
    comm.Parameters.Add(param);


    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@Type";
    param.Value = type;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);

    // execute the stored procedure and save the results in a DataTable
    DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
    return table;
}

我在静态类“GenericDataAccess”中有以下静态方法来执行命令

public static DataTable ExecuteSelectCommand(DbCommand command)
{
    // The DataTable to be returned 
    DataTable table;
    // Execute the command making sure the connection gets closed in the end
    try
    {
        // Open the data connection 
        command.Connection.Open();
        // Execute the command and save the results in a DataTable
        DbDataReader reader = command.ExecuteReader();
        table = new DataTable();
        table.Load(reader);

        // Close the reader 
        reader.Close();
    }
    catch (Exception ex)
    {
        Utilities.LogError(ex);
        throw;
    }
    finally
    {
        // Close the connection
        command.Connection.Close();
    }
    return table;
}

// creates and prepares a new DbCommand object on a new connection
public static DbCommand CreateCommand()
{
    // Obtain the database provider name
    string dataProviderName = NandiConfiguration.DbProviderName;
    // Obtain the database connection string
    string connectionString = NandiConfiguration.DbConnectionString;
    // Create a new data provider factory
    DbProviderFactory factory = DbProviderFactories.
    GetFactory(dataProviderName);
    // Obtain a database specific connection object
    DbConnection conn = factory.CreateConnection();
    // Set the connection string
    conn.ConnectionString = connectionString;
    // Create a database specific command object
    DbCommand comm = conn.CreateCommand();
    // Set the command type to stored procedure
    comm.CommandType = CommandType.StoredProcedure;
    // Return the initialized command object
    return comm;
}

上述结构(静态对象和方法)是否会导致内存泄漏?

如果有并发用户,是否会有用户看到其他用户数据的可能性。

4

1 回答 1

0

共享数据可能是一个问题。但是没有static提到任何字段,所以这对于不同线程上的并发用户是安全的。

内存泄漏 - 没有。可能是高内存消耗,但这仅取决于数据量和数据库设计的效率(WRT 索引等)。

CPU核心,RAM,硬盘,带宽,用户数都与您的问题无关。

于 2013-09-24T11:07:56.757 回答