从sql服务器数据库移动到不需要客户端安装服务器(C#Entity Framework) [英] Moving from a sql server database to one that doesn't require the client to install a server (C# Entity Framework)
问题描述
我试图使用一个sqlite数据库与实体框架。我使用的是.NET 4.5和Visual Studio 2013。
我安装了相应的sqlite nuget软件包,我已经在网上完成了一系列的教程,但 Visual Studio不在乎。
无论我做什么,我都无法连接到我的sqlite数据库。 >
我做了一个包含数据库文件的应用程序。我想要将它作为一个独立的应用程序,不需要额外的安装(sql服务器等)。
我试过了
像我说的,我一直试图让sqlite在Visual Studio中玩得很好,但我没有运气。 p>
我一直在寻找其他数据库类型,但我似乎找不到任何不需要额外的安装和可以使用实体框架。
我已经看到人们建议使用Microsoft Access数据库文件,但我没有运气得到的工作与EF。
我的问题
- 有人知道为什么Visual Studio不给我选择连接到sqlite数据库?
- Microsoft SQL Server Compact数据库是否需要从客户端安装?
- 我可以使用Microsoft Access数据库文件
结束
像往常一样,我可能过度思考这件事,也许有一个非常简单的解决方案,我的问题凝视着我的脸。非常感谢。
编辑:
根据请求,这里是我的连接字符串(尝试获取sqlite工作,而不是工作连接字符串):
<?xml version =1.0encoding =utf-8?>
< configuration>
< configSections>
<! - 有关Entity Framework配置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
< / configSections>
< startup>
< supportedRuntime version =v4.0sku =。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.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< provider invariantName =System.Data.SQLitetype =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数据提供者(Entity Framework 6)invariant =System.Data.SQLite.EF6description =SQLite(实体框架6)的网络框架数据提供者type = .Data.SQLite.EF6.SQLiteProviderFactory,System.Data.SQLite.EF6/>
< add name =SQLite Data Providerinvariant =System.Data.SQLitedescription =。SQLite的Net Framework数据提供者type =System.Data.SQLite.SQLiteFactory,System.Data.SQLite />
< / DbProviderFactories>
< /system.data>
< connectionStrings>
< add name =VVCDbContextconnectionString =Data Source = | DataDirectory | \VVCDatabase.sqliteproviderName =System.Data.SQLite/>
< / connectionStrings>
< / configuration>
至于我用来访问数据库的代码,我使用DbContext访问数据库
其中一个教程我试图遵循是 this one ,当添加新的连接时,他们得到sqlite的选项:
我只能得到选项:
我已经开始空白项目,但我不知道我做错了什么。
1:您需要从无数个sqlite软件包安装正确的vs支持包。我只能使用sqlite使用代码优先,而不是edm向导使用EF6。
2:使用SQL Server Compact无需客户端安装,请参阅我的博客。在VS中安装我的SQLCE工具箱后,您将得到完整的ef工具支持。
3:不知道,不。
4:sqlce或sqlite是你最好的选择,如果它必须是一个免费的工具,需要EF支持。
I'm going to try to keep this as short and to the point as I can.
The Problem
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.).
What I've Tried
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.
My Questions
- 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?
The End
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).
Edit Again
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.
这篇关于从sql服务器数据库移动到不需要客户端安装服务器(C#Entity Framework)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!