本文介绍了如何使用的EntityFramework连接字符串ELMAH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ELMAH记录错误你可以写数据库:

In ELMAH for logging errors to the database you can write:

<errorLog type="Elmah.SqlErrorLog, Elmah"
            connectionStringName="EducoparkEntities"/>

不过,如果我使用的EntityFramework,这不起作用,因为EF连接字符串包含元数据和:

However, if I use EntityFramework, this doesn't work because the connection string for EF contains metadata as well:

<add name="EducoparkEntities" connectionString="metadata=res://*/EducoparkData.csdl|res://*/EducoparkData.ssdl|res://*/EducoparkData.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=(Local);Initial Catalog=...;User Id=...;Password=...;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>

所以,我怎样才能使用的EntityFramework连接字符串中ELMAH?

So, how can I use the EntityFramework connection string in Elmah?

推荐答案

您可以通过提取在实体框架提供的ConnectionStringBuilder数据库连接字符串。

1

You can extract the database connection string via the ConnectionStringBuilder provided in the entity framework.

private string ExtractConnectionStringFromEntityConnectionString(string entityConnectionString)
{
    // create a entity connection string from the input
    EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(entityConnectionString);

    // read the db connectionstring
    return entityBuilder.ProviderConnectionString;
}

2

要堵住数据库连接字符串到ELMAH你将不得不在其设置的的Application_Start (在Global.asax中)

2

To plug that db connection string into Elmah you will have to set it on Application_Start ( in Global.asax)

这篇关于如何使用的EntityFramework连接字符串ELMAH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 06:41