/// <summary> /// 得到Entity的連接字符串 /// </summary> /// <param name="edmxFullName">Edmx的包括命名空間的全名稱</param> /// <param name="server">服務器地址或名稱</param> /// <param name="dadaBase">數據庫</param> /// <param name="usr">用戶</param> /// <param name="pswd">密碼</param> /// <param name="appName">程序名稱</param> /// <returns>Entity連接字符串</returns> public static string GetEntityConnectionString(string edmxFullName, string server, string dadaBase, string usr, string pswd, string appName) { System.Data.EntityClient.EntityConnectionStringBuilder entityConnectionStringBuilder = new System.Data.EntityClient.EntityConnectionStringBuilder(); entityConnectionStringBuilder.Metadata = "res://*/" + edmxFullName + ".csdl|res://*/" + edmxFullName + ".ssdl|res://*/" + edmxFullName + ".msl"; entityConnectionStringBuilder.Provider = "System.Data.SqlClient"; SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.DataSource = server; sqlConnectionStringBuilder.InitialCatalog = dadaBase; sqlConnectionStringBuilder.IntegratedSecurity = true; sqlConnectionStringBuilder.UserID = usr; sqlConnectionStringBuilder.Password = pswd; sqlConnectionStringBuilder.MultipleActiveResultSets = true; sqlConnectionStringBuilder.ApplicationName = appName; entityConnectionStringBuilder.ProviderConnectionString = sqlConnectionStringBuilder.ToString(); return entityConnectionStringBuilder.ConnectionString; }