2016-04-27 23 views
0

私のasp.net MVCアプリケーションでは、私はApp_Dataフォルダに配置したsqlite DB(準備完了)にアクセスします。ASP.net MVC - IISサーバー上のsqliteアクセス "データベースファイルを開くことができません"

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

更新

完全接続文字列:

<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" /> 

これはうまく動作しますローカルホストの下で。

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.] 
... 

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; } 
} 

更新:私は、私は次のエラーを取得するIISサーバーにアプリケーションを公開する場合でも、

<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_Dataフォルダ内から読み込むことはできます。

どうすればこの問題を解決できますか?

ありがとうございます。

答えて

3

SQLiteの接続文字列には、接続文字列のデータソースパラメータに設定されているデータベースファイルの名前だけが必要です。したがって、接続文字列セクションは次のようになります。

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

公開プロセス中にweb.configの値が他の接続と同じになることがわかりました。上記のDbProvidersFactoryを参照してください。 ファイルを手動でコピーするとうまくいきます。 – ratanmalko

0

私はそれを理解しました。接続文字列は何らかの形で、[設定]タブの[Web公開] GUIに別の名前で保存されていました。

関連する問題