Asp.net中使用Sqlite数据库的方法

 更新时间:2009年11月02日 13:50:41   作者:  
Sqlite是最近比较流行的数据库了,拥有比Access高效快速,易操作易实施。完全不需要在客户端进行任何的配置,只需要在站点中引用入DLL文件即可使用了。
实际运用中当我用SqliteAdmin以及SQLite Expert Professional 2软件新建Sqlite数据库的时候在ASP.NET中是无法运用的,老是报错:文件不是一个合法的数据库。后来采用一种方法,就是直接在ASP.NET里面利用引用入的DLL新建数据库就可以用了。

string datasource = "d:\\test.db"; //数据库文件的地址

System.Data.SQLite.SQLiteConnection.CreateFile(datasource); //产生文件

这样产生出的test.db就可以在asp.net中运用了,此时你即使用SqliteAdmin以及SQLite Expert Professional 2软件打开它在里面建表都不影响它的使用了。

对Sqlite的操作其实跟Access非常像的,只不过OleDB开头的都变成了SQLite而已…

.NET Framework Data Provider for ODBC

DRIVER=SQLite3 ODBC Driver; Database=mydb.db; LongNames=0; Timeout=1000; NoTXN=0;SyncPragma=NORMAL; StepAPI=0;
This is just one connection string sample for the wrapping OdbcConnection class that calls the underlying ODBC Driver. See respective ODBC driver for more connection strings to use with this class.

SQLite3 ODBC Driver

DRIVER=SQLite3 ODBC Driver; Database=mydb.db; LongNames=0; Timeout=1000; NoTXN=0;SyncPragma=NORMAL; StepAPI=0;

SQLite.NET

Basic(基本的)
      Data Source=filename;Version=3;
Using UTF16(使用UTF16编码)
      Data Source=filename;Version=3;UseUTF16Encoding=True;
With password(带密码的)
      Data Source=filename;Version=3;Password=myPassword;
Using the pre 3.3x database format(使用3.3x前数据库格式)
      Data Source=filename;Version=3;Legacy Format=True;
Read only connection(只读连接)
      Data Source=filename;Version=3;Read Only=True;
With connection pooling(设置连接池)
      Data Source=filename;Version=3;Pooling=False;Max Pool Size=100;
Using DateTime.Ticks as datetime format()
      Data Source=filename;Version=3;DateTimeFormat=Ticks;
      
The default value is ISO8601 which activates the use of the ISO8601 datetime format
Store GUID as text(把Guid作为文本存储,默认是Binary)
     Data Source=filename;Version=3;BinaryGUID=False;
      如果把Guid作为文本存储需要更多的存储空间
Specify cache size(指定Cache大小)
      
Data Source=filename;Version=3;Cache Size=2000;
      Cache Size 单位是字节
Specify page size(指定页大小)
      Data Source=filename;Version=3;Page Size=1024;
      Page Size 单位是字节
Disable enlistment in distributed transactions
      Data Source=filename;Version=3;Enlist=N;
Disable create database behaviour(禁用创建数据库行为)
     
 Data Source=filename;Version=3;FailIfMissing=True;
      默认情况下,如果数据库文件不存在,会自动创建一个新的,使用这个参数,将不会创建,而是抛出异常信息
Limit the size of database(限制数据库大小
      Data Source=filename;Version=3;Max Page Count=5000;
      The Max Page Count is measured in pages. This parameter limits the maximum number of pages of the database.
Disable the Journal File (禁用日志回滚
      Data Source=filename;Version=3;Journal Mode=Off;
      This one disables the rollback journal entirely.
Persist the Journal File(持久)
      Data Source=filename;Version=3;Journal Mode=Persist;
      This one blanks and leaves the journal file on disk after a commit. Default behaviour is to delete the Journal File after each commit.
Controling file flushing
      Data Source=filename;Version=3;Synchronous=Full;
      Full specifies a full flush to take action after each write. Normal is the default value. Off means that the underlying OS flushes I/O's.

相关文章

  • .NetCore实现上传多文件的示例详解

    .NetCore实现上传多文件的示例详解

    本章和大家分享的是.NetCore的MVC框架上传文件的示例,主要讲的内容有:form方式提交上传,ajax上传,ajax提交+上传进度效果,Task并行处理+ajax提交+上传进度,对大家非常有帮助,感兴趣的朋友跟随小编一起学习吧
    2017-04-04
  • Visual Studio 2017如何用正则修改部分内容详解

    Visual Studio 2017如何用正则修改部分内容详解

    这篇文章主要给大家介绍了关于Visual Studio 2017如何用正则修改部分内容的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-05-05
  • 灵活掌握asp.net中gridview控件的多种使用方法(上)

    灵活掌握asp.net中gridview控件的多种使用方法(上)

    这篇文章向大家推荐如何灵活掌握asp.net中gridview控件的多种使用方法,感兴趣的小伙伴们可以参考一下
    2015-11-11
  • asp.net实现文件无刷新上传方法汇总

    asp.net实现文件无刷新上传方法汇总

    本文给大家介绍的是asp.net实现文件无刷新上传的2种方法,分别是使用swfupload插件和uploadify插件,讲述的十分细致全面,附上示例,有需要的小伙伴可以参考下。
    2015-06-06
  • 在ASP.NET中实现弹出日历的具体方法

    在ASP.NET中实现弹出日历的具体方法

    这篇文章介绍了ASP.NET弹出日历功能的实现方法,有需要的朋友可以参考一下
    2013-07-07
  • .NET webapi某化妆品直播卡死分析

    .NET webapi某化妆品直播卡死分析

    这篇文章主要为大家介绍了.NET webapi化妆品直播卡死分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-06-06
  • .NET获取当前路径的方法汇总

    .NET获取当前路径的方法汇总

    本文汇总了.NET(包括ASP.NET/WinForm等)获取当前路径的各种方法,具有一定的参考价值,下面跟着小编一起来看下吧
    2016-12-12
  • ASP.NET MVC通过勾选checkbox更改select的内容

    ASP.NET MVC通过勾选checkbox更改select的内容

    这篇文章介绍了ASP.NET MVC通过勾选checkbox更改select内容的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-09-09
  • asp.net web页面元素的多语言化(多国语化)实现分享

    asp.net web页面元素的多语言化(多国语化)实现分享

    开发的一些系统,经常要求支持多语言(例如日文,英文等),接下来介绍如何实现asp.net开发中web页面实现页面元素的多语言化(多国语化)感兴趣的朋友可以了解下,或许对你学习有所帮助
    2013-02-02
  • ASP.NET调用javascript脚本的常见方法小结

    ASP.NET调用javascript脚本的常见方法小结

    ASP.NET本身就提供了多种调用javascript脚本的方法,本文总结了六种调用方法,大家根据自己的使用习惯可以选择相应的调用方式了!
    2009-12-12

最新评论