我有這個巨大的系統開始運行昨天。成千上萬的人同時連接..我使用SQL Server 2008和.NET 3.5(C#);數據庫服務器太忙。建議需要打開DataContexts
今天我發現我的數據庫服務器變得非常慢(順便說一句,服務器機器真的,真的能夠輕鬆處理10x這個應用程序,所以我必須搞砸我的連接或什麼)。
首先:My Business類每個都創建一個唯一的DataContext。在課堂上,像這樣:
public class BusProduct : IDisposable
{
//DataContext
DBDataContext db = new DBDataContext();
//Variable of type DAL.Products (that will be set on application level)
public Products _attributes { get; set; }
//Dispose
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
}
/// Constructor
public BusProduct()
{
try
{
//New object
_attributes = new Product();
}
catch (Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
public void Insert()
{
try
{
//Insert data set on _attributes
db.Products.InsertOnSubmit(_attributes);
db.SubmitChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
}
你們怎麼看待這個(每個類一個DataContext)?你會建議什麼?對於巨大的課程好嗎?它甚至好嗎?
我喜歡使它像這樣,主要是因爲返回像IQueryable<Type>
。 (當試圖訪問這種回報的,如果我用一個DataContext
每種方法,將已被佈置)
如果您計劃一個大型系統,同時有數千名用戶同時訪問數據庫,您爲什麼不聘請數據庫專家來設計您的數據庫和查詢?大型高性能數據庫領域是需要多年經驗的專業,應用程序員的創建數據庫性能接近零百分比。 – HLGEM