dotnetnuke 中使用ado.net entityframework 如果在程序中动态调用系统的连接字符串信息

1,打开如下图的Model1.Context.cs文件

 

2,找到

Base:(ConnString.conn)是我改的。默认生成的是"name=实体连接字符串"

Connstring.conn代码如下:

  public static string conn

        {             get             {

                var dnnConnectStringBuilder = DotNetNuke.Data.DataProvider.Instance().GetConnectionStringBuilder();                 dnnConnectStringBuilder.ConnectionString = DotNetNuke.Data.DataProvider.Instance().ConnectionString;

                if (!dnnConnectStringBuilder.ContainsKey("MultipleActiveResultSets"))                 {                     dnnConnectStringBuilder.Add("MultipleActiveResultSets", true);                 }                 else                 {                     dnnConnectStringBuilder["MultipleActiveResultSets"] = true;                 }

                String connectionString = String.Format("metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlClient;provider connection string=\"{0}\"", dnnConnectStringBuilder.ConnectionString);

                return connectionString;             }         }

 

posted @ 2015-01-19 15:51  王鹏飛  阅读(122)  评论(0编辑  收藏  举报