欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-08 21:14:58
实际运用中当我用sqliteadmin以及sqlite expert professional 2软件新建sqlite数据库的时候在asp.net中是无法运用的,老是报错:...
实际运用中当我用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.