ADO.Net Entity Framework: 動態修改連線串資訊
private EOLPDBEntities _db;
private string entityConnectionString = ConfigurationManager.ConnectionStrings["EOLPDBEntities"].ConnectionString;//獲取App.Config裡的連結字串
public EOLPDBEntities GetMyTestEntityNew(string database,string SID)//傳兩個值,用來做修改的引數
{
var ecsb = new EntityConnectionStringBuilder(entityConnectionString);
var scsb = new SqlConnectionStringBuilder(ecsb.ProviderConnectionString);
scsb.InitialCatalog = database;//在此修改引數
scsb.DataSource = SID;;//在此修改引數
ecsb.ProviderConnectionString = scsb.ToString();
_db = new EOLPDBEntities(ecsb.ToString());
return _db; 返回一個數據集
}
使用時 private EOLPDBEntities eolpDB = Conntronstr.GetConnEOLPDBEntities();
打完 收工.......