您好我在以下环境中托管了Web应用程序。 单核,1 GB RAM,40 GB硬盘,700 GB带宽。 Currenlty 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;
}
上述结构(静态对象和方法)会导致内存泄漏吗?
如果有并发用户,用户是否有可能看到其他用户数据。
答案 0 :(得分:0)
共享数据可能是一个问题。但是没有提到static
个字段,因此对于不同线程上的并发用户来说这是安全的。
内存泄漏 - 没有。也许是高内存消耗,但这取决于数据量和数据库设计的效率(W.R.T.索引等)。
CPU内核,RAM,硬盘,带宽,用户数都与您的问题无关。