简体   繁体   English

使用Visual Studio 2013使用SQLITE数据库

[英]Work with SQLITE database using visual studio 2013

I'm Trying to work with SQLITE database using visual studio 2013. I have installed System.Data.SQLite (x86/x64) 1.0.92 to visual studio. 我正在尝试使用Visual Studio 2013使用SQLITE数据库。我已经在Visual Studio中安装了System.Data.SQLite(x86 / x64)1.0.92 And installed the Setups for 64-bit Windows (.NET Framework 4.5) as well. 并安装了用于64位Windows(.NET Framework 4.5)的安装程序。

Problems 问题


  1. It gives me and exception when i'm trying to create database using code first. 当我尝试首先使用代码创建数据库时,它给了我一个例外。

    SQL logic error or missing database no such table: **** SQL逻辑错误或缺少数据库,无此表:****

  2. Cannot create Entity Data Model using existing database. 无法使用现有数据库创建实体数据模型。 No provider is there to create connection. 没有提供者可以创建连接。 So Cannot Use Model First 所以不能先使用模型

  3. Cannot Create data connection. 无法创建数据连接。 There is no SQLITE provider. 没有SQLITE提供程序。 Cannot Use DB First within visual studio 无法在Visual Studio中使用DB First

Success Scenario 成功案例


  1. I can create SQLITE database manually(outside visual studio) and connect to the database and read/write/delete data using Entity Framework/ Manual coding. 我可以手动创建SQLITE数据库(在Visual Studio外部)并使用Entity Framework /手动编码连接到数据库并读取/写入/删除数据。

Is there any way to overcome above problems. 有什么办法可以克服以上问题。

Entity framework 6 for SQLITE is not supporting Database/ Table creation when you use code first. 首次使用代码时,用于SQLITE的实体框架6不支持数据库/表的创建。

You need to create database manually and create tables using ExecuteSqlCommand 您需要手动创建数据库并使用ExecuteSqlCommand创建表

SQLiteConnection.CreateFile(filePath);
Database.ExecuteSqlCommand(SqLiteQueries.CreateEnterpriseApplicationsTable);

OR as mentioned in the question Success Scenario, it support the code first with existing database. 或如问题“成功方案”中所述,它首先支持现有数据库的代码。

I believe there is. 我相信有。

  • Target .NET Framework 4.0 from project properties. 从项目属性中定位.NET Framework 4.0。
  • Change what is in your App.config file with this (After the line that declares xml version); 以此更改您的App.config文件中的内容(在声明xml版本的行之后);

< configuration > < startup useLegacyV2RuntimeActivationPolicy ="true" > < suppurtedRuntime version="v4.0"/> < / startup> < /configuration > (I couldn't insert the XAML code here correctly so check before copying or type it manually) < configuration > < startup useLegacyV2RuntimeActivationPolicy ="true" > < suppurtedRuntime版本=“ v4.0” /> < /启动> < /configuration >(我无法在此处正确插入XAML代码,因此请在复制或手动键入之前进行检查)

-In case there is a problem with your connection string use; -如果您的连接字符串使用有问题;

  public static string ConnectionString = @"Data Source = databasename.db;Version=3; "

The last thing means that I suggest you to use SQLite3. 最后一件事意味着我建议您使用SQLite3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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