Elmah没有创建Sqlite表和存储过程

问题描述 投票:0回答:1

我正在使用Elmah使用SqlLite数据库记录ASP.NET MVC中的未处理异常。当我用下面的SqlLite数据库配置Elmah时

<elmah>
<!--
    See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
    more information on remote access and securing ELMAH.
-->
<security allowRemoteAccess="false" />
<errorLog type="Elmah.SQLiteErrorLog, Elmah" connectionStringName="Elmah" />
</elmah>

使用下面的connectionstring

<connectionStrings>
    <add name="Elmah" connectionString="data source=~/App_Data/Error.db" />
  </connectionStrings>

它抛出了这个例外

SQLiteException (0x1): SQL logic error
    no such table: Error]
       System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain) +1239
       System.Data.SQLite.SQLiteCommand.BuildNextCommand() +374
       System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index) +18
       System.Data.SQLite.SQLiteDataReader.NextResult() +309
       System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) +266
       System.Data.`enter code here`SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) +45
       System.Data.SQLite.SQLiteCommand.ExecuteReader() +21
       Elmah.SQLiteErrorLog.GetErrors(Int32 pageIndex, Int32 pageSize, IList errorEntryList) +235
       Elmah.ErrorLogPage.OnLoad(EventArgs e) +336
       System.Web.UI.Control.LoadRecursive() +59
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678`

任何人都可以告诉我我哪里错了吗?

我如何使用Elmah配置Sqlite数据库进行日志记录?

c# asp.net-mvc sqlite elmah
1个回答
0
投票

您不需要手动创建数据库或运行脚本,因为SQLLiteErrorLog does this automatically。我刚测试了这个,它通过这样做:

  1. 创建一个新的Web项目。
  2. 安装ELMAH NuGet包。
  3. 安装System.Data.SQLite NuGet包。
  4. 将以下内容添加到web.config
<connectionStrings>
    <add name="Elmah" connectionString="data source=~/App_Data/Error.db" />
</connectionStrings>

...

<elmah>
    <security allowRemoteAccess="false" />
    <errorLog type="Elmah.SQLiteErrorLog, Elmah" connectionStringName="Elmah" />
</elmah>
  1. 点击F5并导航到/elmah.axd

我做了上述步骤,并在我的一个控制器中强制执行异常并请求该路由。 Error.db文件已成功创建,并记录错误。

如果Error.db文件夹中已有名为App_Data的文件,请尝试删除该文件并重试。

© www.soinside.com 2019 - 2024. All rights reserved.