Using Entity Framework with an SQL Compact Private Installation

后端 未结 5 1784
南旧
南旧 2020-11-28 21:53

I am using Entity Framework 4 in a desktop application with SQL Compact. I want to use a private installation of SQL Compact with my application, so that my install

相关标签:
5条回答
  • 2020-11-28 22:36

    Just for the record, with SQL CE 4 the web.config entries are the following:

      <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.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
      </system.data>
    

    Version=4.0.0.1 in case of a private deployement and Version=4.0.0.0 in case of a general deployment.

    0 讨论(0)
  • 2020-11-28 22:37

    Being stuck with the same problem,

    "the specified store provider cannot be found in the configuration or is not valid."

    I came around this post. I tried almost everything. I had installed "System.Data.SqlServerCe" using nugets.

    So i already had below line of code added in my web.config

    <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" />
      <!--<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />-->
      <!--<add name="Microsoft EntityClient" invariant="System.Data.EntityClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.EntityClient, System.Data.EntityClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />-->
    </DbProviderFactories>
    

    Still the error continued..

    I got rid of problem by uncommenting the last two commented lines in above code...so now it becomes

    <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" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <add name="Microsoft EntityClient" invariant="System.Data.EntityClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.EntityClient, System.Data.EntityClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
    

    Hope it helps.. Thanks.

    0 讨论(0)
  • 2020-11-28 22:54

    I figured out how to do it, thanks to a blog post by Steve Lasker. Basically, here is what you have to do:

    (1) Set a reference to System.Data.SqlServerCe.dll in your project. Set the CopyLocal property to True.

    (2) In the App.config for your project, add the following XML markup. It tells EntityFramework to look to your private installation of SQL Compact for its data provider:

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

    (3) In the Setup project, add the following files to the Application Folder in the File System Editor:

    • sqlcecompact35.dll
    • sqlceme35.dll
    • sqlcese35.dll
    • System.Data.SqlServerCe.Entity.dll
    0 讨论(0)
  • 2020-11-28 22:54

    This is what worked for me:

    You've got a machine.config file for dotNet versions 2.0 and 4.0:

    dotNET 2.0

    C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
    dotNet 4.0
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

    If you open up the file for version 2.0, you'll see that it has a <system.data> node, which probably looks something like this:

    <system.data>
        <DbProviderFactories>
            <add name="Odbc Data Provider" ... stuff here ... />
            <add name="OracleClient Data Provider" ... stuff here ...>
            ... more lines similar to the one above ...
            <add name="Microsoft SQL Server Compact Data Provider" Invariant="System.Data.SqlServerCe.3.5" ...>
        </DbProviderFactories>
    </system.data>
    

    Whereas, if you open up the one for dotNet 4.0, it looks rather more miserably like:

    <system.data>
        <DbProviderFactories>        
        </DbProviderFactories>
    </system.data>
    

    Or maybe it doesn't even have a <system.data> node at all !!! In either case, simply copy the <system.data> node in it's entirety from the machine.config file for v2 to the one for v4.

    SIDE NOTE

    If you are having trouble saving your edit of the v4 machine.config, then you might have to right click a couple of times when clicking on the editor launch icon so as to get to the run in admin mode.

    0 讨论(0)
  • 2020-11-28 22:59

    thanks for your tip - helped me alot. There's a post on the SQL Server Compact-Team blog which add some additional information for the Sql Server Compact 3.5 SP2 release.

    After struggling for a while with the private deployment of sql server compact i found out some additional requirements.

    I tried out my app on several different systems and recognized that my app not worked properly on some of them.

    Example: Try this:

    -I've set up a clean winxp sp3 installation

    -installed the .net Framework 4.0 extended

    -deployed my app to the new installation (including all necessary dll's and tweaks described in your/sql server compact team blog post's)

    So, after some research i found out that in addition to the .net framework 4 installation i had to install the .net framework 2 as well and it worked fine.

    So here is my question: which component is used by the sql server compact edition which is not contained in the .net framework 4?

    I don't want overload my setup and chain two frameworks to my bootstrapper... Does anybody know any good Tip?

    Many thanks to the sql server compact Team!

    SQL Server Compact v3.5 depends on ‘Visual C++ Runtime 2005 (or 8.0)’ (also known as CRT80). We package the CRT80 modules in our MSI. In case of private deployment,

    you need to take care of this dependency. Things work with .NET FX v2.0 on the system automatically because .NET FX v2.0 also packages and installs CRT80 modules.

    Thanks

    0 讨论(0)
提交回复
热议问题