2017-06-13 8 views
0

私はEntity FrameworkとCompact DBを使用するASP.NET MVC Webアプリケーションを持っています - "db.sdf"または "db.mdf"ファイル。Azure 1時間Webアプリケーションtry - SQL Compact db

localhostで動作します。

しかし、私はAzureに1時間試しWebアプリケーションとして公開したいと思います。

私はこのエラーを得た:

The Entity Framework provider type 'System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application.

何が起こっていますか?私はパッケージインストールされている:

EF.SqlServer 
EF.SqlServerCompact 
System.Data.SqlServerCe 

をそしてweb.configファイルに見えます:

<configSections> 
    <section name="entityFramework" 
      type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, 
     EntityFramework, Version=6.0.0.0, Culture=neutral, 
     PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
</configSections> 

<connectionStrings> 
    <add name="DefaultConnection" connectionString="Data 
    Source=|DataDirectory|db.sdf" 
    providerName="System.Data.SqlServerCe.4.0" /> 
</connectionStrings> 

<entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"> 
     <parameters> 
      <parameter value="System.Data.SqlServerCe.4.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
     <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" /> 
    </providers> 
</entityFramework> 

<system.data> 
    <DbProviderFactories> 
     <remove invariant="System.Data.SqlServerCe.4.0" /> 
     <add name="Microsoft SQL Server Compact Data Provider 4.0" 
      invariant="System.Data.SqlServerCe.4.0" 
      description=".NET Framework Data Provider for Microsoft SQL Server Compact" 
      type="System.Data.SqlServerCe.SqlCeProviderFactory, 
       System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, 
      PublicKeyToken=89845dcd8080cc91" /> 
    </DbProviderFactories> 
</system.data> 
+0

"*しかし、私はAzureに1時間試しWebアプリとして公開したい*" - これが何を意味するのかわからない。 –

+0

ファイルを "ローカルにコピー"する必要があります。これを行うには、参照を開き、SqlServerCe.4.0をクリックし、プロパティウィンドウで[ローカルにコピー]を選択します。これは、ファイルがデプロイメントパッケージの一部であることを確認します。 –

答えて

0

あなたはSQLコンパクトデータベースは、AzureのWebアプリケーションに仕事ができるかどうかをチェックしますか?私はWebアプリケーションでそれをテストします。それは正常に動作することができます。あなたは開発環境のためにそれを使うことができます。プロダクション環境では、Azure SQL Databaseをお勧めします。

'System.Data.SqlServerCe.4.0' could not be loaded.

.NETアプリケーションでSQL Compactを使用するには、NuGetから次のパッケージをインストールする必要があります。

Microsoft.SqlServer.Compact 
EntityFramework.SqlServerCompact 

その後、2つの.NETアセンブリと複数のネイティブアセンブリが、アプリケーションによって参照されます。あなたの問題のために

enter image description here

enter image description here

、コピーローカルプロパティが2つの.NETアセンブリのための '真' に設定されているかどうかを確認してください。

enter image description here

SQLコンパクトを使用する前に、次のようにweb.configファイル内の接続文字列を設定する必要があります。

<add name="DefaultConnection" connectionString="Data Source=|DataDirectory|\myDB.mdf" providerName="System.Data.SqlServerCe.4.0"/> 

その後、SQL Compact by EFを使用できます。下記のコードは参照用です。

public class MyDataContext : DbContext 
{ 
    public MyDataContext():base("DefaultConnection") { } 

    public DbSet<Student> Students { get; set; } 
} 

public class Student 
{ 
    public int ID { get; set; } 

    public string Name { get; set; } 
} 

public ActionResult Index() 
{ 
    MyDataContext context = new MyDataContext(); 
    context.Students.Add(new Student() { ID = 1, Name = "name1" }); 
    context.SaveChanges(); 
    return Content("Create data OK!"); 
} 

あなたは、コード最初のモデルを使用する場合は、あなたも、このフォルダはデフォルトで作成されていない場合はAzureのWebアプリケーションにWebアプリケーションをデプロイした後wwwrootフォルダの下にApp_Dataフォルダを作成する必要があります。

+0

更新情報問題が解決したかどうか、有回答の場合は有益な回答を回答としてマークしてください。ご不明な点がございましたら、お気軽にお知らせください。 – Amor

関連する問題