Asp.net中使用Sqlite数据库的方法_实用技巧

实际运用中当我用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.

时间: 2024-08-03 17:03:23

Asp.net中使用Sqlite数据库的方法_实用技巧的相关文章

在ASP.Net中实现RSA加密的方法_实用技巧

在我们实际运用中,加密是保证数据安全的重要手段.以前使用ASP时,对数据加密可以使用MD5和SHA1算法,这两种算法虽然快捷有效,但是无法对通过它们加密的密文进行反运算,即是解密.因此需要解密数据的场合,这两种方法就不太适合了.当然你也可以自己编写适用的加密和解密程序,不过这对编写者的数学水平有很高的要求,一般人是很难做到的. 现在,随着ASP.Net的推出,彻底改变了以前ASP下的编程模式.我们能够利用.Net Framework中的类提供的加密服务来保证数据安全.目前应用较为广泛的加密方法是

利用Timer在ASP.NET中实现计划任务的方法_实用技巧

.NET Framework中为我们提供了3种类型的Timer,分别是: Server Timer(System.Timers.Timer),Thread Timer(System.Threading.Timer )和Windows Timer(System.Windows.Forms.Timer). 其中Windows Timer和WinAPI中的Timer一样,是基于消息的,而且是单线程的.另外两个Timer则不同于Windows Timer,它们是基于ThreadPool的,这样最大的好处

ASP.NET中使用TreeView显示文件的方法_实用技巧

在ASP.NET中,TreeView的使用很普遍,把它利用上来 首先加入TreeView控件 <asp:TreeView ID="driverInfoView" runat="server" ImageSet="XPFileExplorer" OnTreeNodePopulate="driverInfoView_TreeNodePopulate"> </asp:TreeView> 当页面加载的时候,写下

区分ASP.NET中get方法和post方法_实用技巧

在网页设计中,无论是动态还是静态,get方法是默认的,它在URL地址长度是有限的,所以get请求方法能传送的数据也是有限的,一般get方法能传递256字节的数据,当get请求方法传递的数据长度不能满足需求时,就需要采用另一种请求方法post,post方法可传递的数据最大值为2mb相应地,读取post方法传递过来的数据时,需要采用form方法来获取:post方法在aspx页面执行时,地址栏看不到传送过来的参数数据,更加有利于页面的安全,所以一般情况采用post方法传送页面数据. 这里举个简单的例子

ASP.NET oledb连接Access数据库的方法_实用技巧

使用OleDBCommand相关操作类需要引入System.Data.OleDb命名空间. 通过连接一个带密码的access数据库 读取其中的数据并置入表格中显示,验证连接和命令使用正确性. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Da

详述ASP.Net中页面之间传参方法_实用技巧

ASP.NET提供了卓越的事件驱动编程模型,让开发者简化了应用程序的总体设计,但是这个也造成了它固有的一些问题,例如,使用传统的ASP里,我们可以通过使用POST方法很容易地实现页面间传递值,同样的事情,在使用事件驱动编程模型的ASP.NET就不是那么容易了,当然了,我们仍然有一些方法可以实现同样的功能. 本文将试着使用不同的可能的方法来解决这个问题,但可以预见是,本文将包含使用querystring,session变量以及server.Transfer方法来实现页面间的值传递. 使用Query

ASP.NET缓存管理的几种方法_实用技巧

尽管缓存管理在Windows应用程序中已经不再是个问题,但在web环境下依然是个挑战.因为HTTP是一个无状态的协议并且web服务无法识别不同请求的用户.识别不同的请求究竟是哪个特定用户发出的,并且存储这些信息以便它在以后请求中能被重新使用,对我们来说非常重要.ASP.NET提供了很多特性用来在客户端和服务器端存储这些数据,但是有时我们会对"我们什么时候使用它们(哪个)"感到疑惑.在ASP.NET中,我们会遇到像Session,Application以及Cache这些对象,为了有效地在

asp.net中EXCEL数据导入到数据库的方法_实用技巧

本文实例讲述了asp.net中EXCEL数据导入到数据库的方法.分享给大家供大家参考.具体分析如下: excel是办公中非常常用的一个办公表格了,但我们在开发中通常会需要直接把excel数据快速导入到数据库中了,这里整理了一个asp.net中EXCEL数据导入到数据库的例子供各位参考学习. 注意:EXCEL中的第一行不能导入.下面是源码:IntoExcel.aspx: 复制代码 代码如下: <%@ Page  AutoEventWireup="true" CodeFile=&qu

asp.net GridView中使用RadioButton单选按钮的方法_实用技巧

本文实例讲述了asp.net GridView中使用RadioButton单选按钮的方法.分享给大家供大家参考,具体如下: 在GridView里做单选按钮,我用了三种方法 第一种方法:在GridView的模版列里加服务器端控件RadioButton,使用js控制单选 使用模版列里加RadioButton <script type="text/javascript"> function setRadio(nowRadio) { var myForm,objRadio; myF