首页 > 数据库技术 > 详细

EF之MSSQL分布式部署一:EFContext自定义数据库链接

时间:2014-11-30 22:56:21      阅读:276      评论:0      收藏:0      [点我收藏+]
不废话,上代码:
来源:http://bbs.csdn.net/topics/390823046
 
        /// <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;
        } 

  

EF之MSSQL分布式部署一:EFContext自定义数据库链接

原文:http://www.cnblogs.com/lmBlock/p/4133680.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!