【问题标题】:Elmah not creating the SqlLite tables and stored proceduresElmah 没有创建 SqlLite 表和存储过程
【发布时间】:2019-07-08 20:53:40
【问题描述】:

我正在使用 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>

使用下面的连接字符串

<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 配置 SqlLite 数据库以进行日志记录?

【问题讨论】:

  • 这里有同样的问题。我已经在本地成功配置了 elmah&sqlite,使用 Visual Studio 运行我的 wcf。当我发布到远程 IIS 服务器时(有些在这里挣扎link),它会抛出完全相同的错误。似乎我们有相同的 web.config,除了我在 &lt;webServer&gt; 中有这个:&lt;handlers&gt; &lt;add name="ELMAH" verb="POST,GET,HEAD" path="elmah/default.aspx" type="Elmah.ErrorLogPageFactory, Elmah"/&gt; &lt;/handlers&gt; &lt;modules runAllManagedModulesForAllRequests="true"&gt; &lt;add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/&gt; &lt;/modules&gt;

标签: c# asp.net-mvc sqlite elmah


【解决方案1】:

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

  1. 创建一个新的网络项目。
  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 文件已成功创建并记录错误。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多