C# ASP.net MVC-IIS服务器上的sqlite访问”;无法打开数据库文件";

C# ASP.net MVC-IIS服务器上的sqlite访问”;无法打开数据库文件";,c#,asp.net,asp.net-mvc,sqlite,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc,Sqlite,Asp.net Mvc 5,在我的asp.net MVC应用程序中,我访问一个放置在App_数据文件夹中的sqlite DB(仅就绪) connection string='data source=|DataDirectory|tutorials.db' 更新: <DbProviderFactories> <remove invariant="System.Data.SQLite" /> <add name="SQLite Data Provider" invariant="S

在我的asp.net MVC应用程序中,我访问一个放置在App_数据文件夹中的sqlite DB(仅就绪)

   connection string='data source=|DataDirectory|tutorials.db'
更新

<DbProviderFactories>
  <remove invariant="System.Data.SQLite" />
  <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
  <remove invariant="System.Data.SQLite.EF6" />
  <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
</DbProviderFactories>
完成连接字符串:

<add name="myEntities" connectionString="metadata=res://*/Models.MyData.csdl|res://*/Models.MyData.ssdl|res://*/Models.MyData.msl;provider=System.Data.SQLite.EF6;provider connection string='data source=|DataDirectory|myDB.db'" providerName="System.Data.EntityClient" />

在localhost下,这一切都很好。但是,当我将应用程序发布到IIS服务器时,会出现以下错误:

unable to open database file

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.Data.SQLite.SQLiteException: unable to open database file

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: 


[SQLiteException (0xe): unable to open database file]
   System.Data.SQLite.SQLite3.Open(String strFilename, String vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, Int32 maxPoolSize, Boolean usePool) +627
   System.Data.SQLite.SQLiteConnection.Open() +5031
   System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c) +10
   System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +72
   System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +359
   System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2() +55
   System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation) +9
   System.Data.Entity.Core.EntityClient.EntityConnection.Open() +253

[EntityException: The underlying provider failed on Open.]
...
无法打开数据库文件
描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。
异常详细信息:System.Data.SQLite.SQLiteException:无法打开数据库文件
源错误:
在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别。
堆栈跟踪:
[SQLiteException(0xe):无法打开数据库文件]
System.Data.SQLite.SQLite3.Open(字符串strFilename、字符串vfsName、SQLiteConnectionFlags connectionFlags、SQLiteOpenFlagsEnum openFlags、Int32 maxPoolSize、Boolean usePool)+627
System.Data.SQLite.SQLiteConnection.Open()+5031
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b_uu36(DbConnection t,DbConnectionInterceptionContext c)+10
System.Data.Entity.Infrastructure.InternalDispatcher`1.Dispatch(目标目标,操作`2操作,TInterceptionContext拦截上下文,操作`3执行,操作`3执行)+72
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection-connection,DbInterceptionContext-interceptionContext)+359
System.Data.Entity.Core.EntityClient.EntityConnection.b__2()+55
System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(操作操作)+9
System.Data.Entity.Core.EntityClient.EntityConnection.Open()+253
[EntityException:基础提供程序在打开时失败。]
...
DbContext:

public partial class myEntities : DbContext
{
    public myEntities()
        : base("name=myEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<MyData> myData { get; set; }
}
公共部分类myenties:DbContext
{
公共慈善机构()
:base(“name=myEntities”)
{
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
抛出新代码FirstException();
}
公共虚拟数据库集myData{get;set;}
}
更新

<DbProviderFactories>
  <remove invariant="System.Data.SQLite" />
  <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
  <remove invariant="System.Data.SQLite.EF6" />
  <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
</DbProviderFactories>

我不确定是连接字符串还是其他问题。 不过,我确实更改了IIS中的网站主目录

我可以从App_数据文件夹中加载其他文件

我怎样才能解决这个问题


谢谢。

SQLite的连接字符串只需要连接字符串的数据源参数中设置的数据库文件名。因此,您的连接字符串部分可以如下所示:

<connectionStrings><add name="YourConnection"
     connectionString="data source=|DataDirectory|YourDB.sqlite"
     providerName="System.Data.SqlLite"/></connectionStrings>

SQLite的连接字符串只需要在连接字符串的数据源参数中设置的数据库文件名。因此,您的连接字符串部分可以如下所示:

<connectionStrings><add name="YourConnection"
     connectionString="data source=|DataDirectory|YourDB.sqlite"
     providerName="System.Data.SqlLite"/></connectionStrings>


我想出来了。在“设置”选项卡的“发布Web”GUI中,连接字符串以不同的名称保存。

我找到了它。在“设置”选项卡的“发布Web”GUI中,连接字符串以不同的名称保存。

我注意到,在发布过程中,Web.config的值与我在另一个连接中的值相同。请参阅上面的DbProvidersFactory。当我手动复制文件时,它工作正常。我注意到在发布过程中,web.config的值与我在另一个连接中的值相同。请参阅上面的DbProvidersFactory。当我手动复制文件时,它工作正常。