简体   繁体   中英

Moving from a sql server database to one that doesn't require the client to install a server (C# Entity Framework)

I'm going to try to keep this as short and to the point as I can.

I'm trying to use a sqlite database with the entity framework. I am using .NET 4.5, and Visual Studio 2013.

I've installed the appropriate sqlite nuget packages, and I've followed a bunch of tutorials online to accomplish this, but Visual Studio doesn't care .

No matter what I do, I can't connect to my sqlite database.

I made an application that includes a database file. I want to be able to distribute it as a standalone application that doesn't require additional installations (sql server, etc.).

Like I said, I've been trying to get sqlite to play nice with Visual Studio all night, but I've had no luck.

I've been looking around for other database types, but I can't seem to find any that don't require additional installs AND can use the entity framework.

I've seen people suggest using a Microsoft Access database file, but I haven't had luck getting that to work with EF either.

  • Does anybody know why Visual Studio doesn't give me the option to connect to a sqlite database?
  • Does a Microsoft SQL Server Compact database require an install from the client?
    • If not, how can I use it with my existing code?
  • Can I use a Microsoft Access database file with the Entity Framework?
  • Is there a better option that I have not pursued yet?

Like usual, I am probably over-thinking this whole thing, and there is probably a really simple solution to my problem staring me in the face. Any feedback/help would be greatly appreciated.

Thanks in advance!

Edit:

As requested, here is my connection string (attempting to get sqlite to work, not the working connection string):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="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" />
    <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="VVCDbContext" connectionString="Data Source=|DataDirectory|\VVCDatabase.sqlite" providerName="System.Data.SQLite" />
  </connectionStrings>
</configuration>

As far as the code I use to access the database, I use a DbContext to access the database (which works with my current setup).

One of the tutorials I have tried to follow is this one , and when adding a new connection, they get the option for sqlite:

I only get the options:

I've started blank projects, and followed everything exactly, but I have no idea what I'm doing wrong.

1: You need to install the correct vs support package from the myriad of sqlite packages. And I have only been able to make sqlite Work with EF6 using Code First, not the edm wizard.

2: With SQL Server Compact no client install is required, see my blog for details. With my SQLCE Toolbox installed in VS, you get full ef tooling support.

3: Not as far as I know, no.

4: sqlce or sqlite are your best options, if it must be a free Tool, and EF support is required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM