6

Tôi cố gắng chạy ELMAH với dự án ASP.NET MVC 2 của tôi nhưng có một số vấn đề để làm cho nó hoạt động với cơ sở dữ liệu SQL Server 2008 R2 của tôi.ELMAH và SQL Server 2008 R2?

Đây là những gì tôi đã làm.

  • Chạy dbscript trong cơ sở dữ liệu của tôi, vô tình tôi chạy nó hai lần nhưng có vẻ như không quan trọng trong trường hợp này.

  • Thêm phần sau để tôi web.config (dưới configSection):

    <elmah> 
        <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="MyEntities" /> 
    </elmah> 
    
  • Đây là cách chuỗi kết nối Entity Framework tôi trông giống như:

    <add name="MyEntities" 
        connectionString="metadata=res://*/Models.Model.MyEntities.csdl|res://*/Models.Model.MyEntities.ssdl|res://*/Models.Model.MyEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=000.000.000.000;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=[username];Password=[password];MultipleActiveResultSets=True&quot;" 
        providerName="System.Data.EntityClient" /> 
    

Khi quý khách đến thăm quản trị/elmah/trang Tôi nhận được ngoại lệ sau:

Keyword not supported: 'metadata'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported: 'metadata'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: Keyword not supported: 'metadata'.]
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +5110868
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +98
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +64
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +150
System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +59

Tôi đang làm gì sai?

Trả lời

8

Chuỗi kết nối khung thực thể khác với chuỗi kết nối sqlclient và chúng không tương thích. Bạn phải sử dụng chuỗi kết nối sqlclient để làm việc với elmah. Nhìn vào trang web này để xem các chuỗi kết nối hợp lệ: http://connectionstrings.com/sql-server-2008

Các vấn đề liên quan