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

所属分类: 网络编程 / ASP.NET 阅读数: 1798
收藏 0 赞 0 分享
实际运用中当我用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.
更多精彩内容其他人还在看

Asp.Net二级域名共享Forms身份验证、下载站/图片站的授权访问控制

我们平时一般在做图片或者文件下载权限控制的时候基本都是控制到下载页面的,当你的下载地址暴露后,浏览者就直接可以通过文件地址进行下载了,这时候也就出现了我们常说的盗链
收藏 0 赞 0 分享

在ASP.NET中下载文件的实现代码

通过ASP.NET来下载文件,这个问题可大可小,我们先从小的开始。当我们要让用户下载一个文件
收藏 0 赞 0 分享

asp.net下日期和时间处理的类库

发一个专门处理时间和日期的类库,记录以备查询
收藏 0 赞 0 分享

LINQ重写博客垃圾图片回收算法

本人博客后台管理模块有个功能,可以扫描图片上传文件夹下所有未被引用的博客
收藏 0 赞 0 分享

C#多线程Singleton(单件)模式模板

下面是一个C#多线程单件模式的代码模板。把T换成你自己的类型就可以使用了。其精妙之处就在于用lock语句锁定资源来避免多线程同时走入if语句去创建多个对象
收藏 0 赞 0 分享

URL重写及干掉ASP.NET试图状态的实现方法

URL重写已经很普遍了,但基本上大部分的URL重写都不支持页面的相对路径,所有如果想在已经开发好的项目中添加还是有压力的,第二就是例如微软的那个URL重写是根据正则表达式来处理的,那样是很好,但也有不足之处,就是不方便定位到某个页面只能有哪些参数
收藏 0 赞 0 分享

正则方式的自动小偷抓网程序

公司里面有许多数据没人去录入,做一个抓取网页的程序,以前做CMS系统的时候涉及过,不过这次的处理HTML上和以前做了些区别
收藏 0 赞 0 分享

asp.net生成缩略图实现代码

此文件imgSmall.ashx专门用来生成图片的缩略图,可以减少服务器压力,降低网络流量,初学者必备
收藏 0 赞 0 分享

asp.net richTextBox中高亮显示选中字符串或文本

最近开发程序需要对一段文本中的某个字符串进行高亮显示,网上找了下资料
收藏 0 赞 0 分享

ASP.net的验证控件浅析

前些天在做注册页面的验证的时候,用了下ASP.net的验证控件,有一些体会,特写下这篇博客,如果有朋友有不同ideas,欢迎大家留言
收藏 0 赞 0 分享
查看更多