Sqlite 管理工具 SQLiteDeveloper及破解

功能特点

表结构设计,数据维护,ddl生成,加密数据库支持,sqlite2,3支持

唯一缺憾,收费,有试用期

破解方法:

注册表删除 HKEY_CURRENT_USER\SharpPlus\SqliteDev 下的 StartDate 可继续使用

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. //这个文件是预先生成的数据库文件
  4. string sqliteFilePath = "Data Source=" + Server.MapPath("~/App_Data/demo2012.db");
  5. DataSet ds = new DataSet();
  6. MSCL.SqliteHelper sqlite = new MSCL.SqliteHelper(sqliteFilePath);
  7. ds = sqlite.ExecuteDataSet("Select * From LoginTable",CommandType.Text);
  8. gv1.DataSource = ds;
  9. gv1.DataBind();
  10. }
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data.SQLite;
  5. using System.Data;
  6. using System.Data.Common;
  7.  
  8. namespace MSCL
  9. {
  10. /// <summary>
  11. /// 本类为SQLite数据库帮助类
  12. /// 轻量级数据库SQLite的连接字符串写法:"Data Source=D:\database\test.s3db"
  13. /// 轻量级数据库SQLite的加密后的连接字符串写法:"Data Source=Maximus.db;Version=3;Password=myPassword;"
  14. /// </summary>
  15. public class SqliteHelper
  16. {
  17. //数据库连接字符串
  18. private readonly string _conn = string.Empty;
  19.  
  20. public SqliteHelper(string connectionString)
  21. {
  22. _conn = connectionString;
  23. }
  24.  
  25. #region ExecuteNonQuery
  26. /// <summary>
  27. /// 执行数据库操作(新增、更新或删除)
  28. /// </summary>
  29. /// <param name="connectionString">连接字符串</param>
  30. /// <param name="cmd">SqlCommand对象</param>
  31. /// <returns>所受影响的行数</returns>
  32. public int ExecuteNonQuery(SQLiteCommand cmd)
  33. {
  34. int result = 0;
  35. if (string.IsNullOrEmpty(_conn))
  36. throw new ArgumentNullException("Connection string is missing.");
  37. using (SQLiteConnection con = new SQLiteConnection(_conn))
  38. {
  39. SQLiteTransaction trans = null;
  40. PrepareCommand(cmd, con, ref trans, true, cmd.CommandType, cmd.CommandText);
  41. try
  42. {
  43. result = cmd.ExecuteNonQuery();
  44. trans.Commit();
  45. }
  46. catch (Exception ex)
  47. {
  48. trans.Rollback();
  49. throw ex;
  50. }
  51. }
  52. return result;
  53. }
  54.  
  55. /// <summary>
  56. /// 执行数据库操作(新增、更新或删除)
  57. /// </summary>
  58. /// <param name="connectionString">连接字符串</param>
  59. /// <param name="commandText">执行语句或存储过程名</param>
  60. /// <param name="commandType">执行类型</param>
  61. /// <returns>所受影响的行数</returns>
  62. public int ExecuteNonQuery(string commandText, CommandType commandType)
  63. {
  64. int result = 0;
  65. if (string.IsNullOrEmpty(_conn))
  66. throw new ArgumentNullException("Connection string is missing.");
  67. if (string.IsNullOrEmpty(commandText))
  68. throw new ArgumentNullException("commandText");
  69. SQLiteCommand cmd = new SQLiteCommand();
  70. using (SQLiteConnection con = new SQLiteConnection(_conn))
  71. {
  72. SQLiteTransaction trans = null;
  73. PrepareCommand(cmd, con, ref trans, true, commandType, commandText);
  74. try
  75. {
  76. result = cmd.ExecuteNonQuery();
  77. trans.Commit();
  78. }
  79. catch (Exception ex)
  80. {
  81. trans.Rollback();
  82. throw ex;
  83. }
  84. }
  85. return result;
  86. }
  87.  
  88. /// <summary>
  89. /// 执行数据库操作(新增、更新或删除)
  90. /// </summary>
  91. /// <param name="connectionString">连接字符串</param>
  92. /// <param name="commandText">执行语句或存储过程名</param>
  93. /// <param name="commandType">执行类型</param>
  94. /// <param name="cmdParms">SQL参数对象</param>
  95. /// <returns>所受影响的行数</returns>
  96. public int ExecuteNonQuery(string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
  97. {
  98. int result = 0;
  99. if (string.IsNullOrEmpty(_conn))
  100. throw new ArgumentNullException("Connection string is missing.");
  101. if (string.IsNullOrEmpty(commandText))
  102. throw new ArgumentNullException("commandText");
  103.  
  104. SQLiteCommand cmd = new SQLiteCommand();
  105. using (SQLiteConnection con = new SQLiteConnection(_conn))
  106. {
  107. SQLiteTransaction trans = null;
  108. PrepareCommand(cmd, con, ref trans, true, commandType, commandText, cmdParms);
  109. try
  110. {
  111. result = cmd.ExecuteNonQuery();
  112. trans.Commit();
  113. }
  114. catch (Exception ex)
  115. {
  116. trans.Rollback();
  117. throw ex;
  118. }
  119. }
  120. return result;
  121. }
  122. #endregion
  123.  
  124. #region ExecuteScalar
  125. /// <summary>
  126. /// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
  127. /// </summary>
  128. /// <param name="connectionString">连接字符串</param>
  129. /// <param name="cmd">SqlCommand对象</param>
  130. /// <returns>查询所得的第1行第1列数据</returns>
  131. public object ExecuteScalar(SQLiteCommand cmd)
  132. {
  133. object result = 0;
  134. if (string.IsNullOrEmpty(_conn))
  135. throw new ArgumentNullException("Connection string is missing.");
  136. using (SQLiteConnection con = new SQLiteConnection(_conn))
  137. {
  138. SQLiteTransaction trans = null;
  139. PrepareCommand(cmd, con, ref trans, true, cmd.CommandType, cmd.CommandText);
  140. try
  141. {
  142. result = cmd.ExecuteScalar();
  143. trans.Commit();
  144. }
  145. catch (Exception ex)
  146. {
  147. trans.Rollback();
  148. throw ex;
  149. }
  150. }
  151. return result;
  152. }
  153.  
  154. /// <summary>
  155. /// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
  156. /// </summary>
  157. /// <param name="connectionString">连接字符串</param>
  158. /// <param name="commandText">执行语句或存储过程名</param>
  159. /// <param name="commandType">执行类型</param>
  160. /// <returns>查询所得的第1行第1列数据</returns>
  161. public object ExecuteScalar(string commandText, CommandType commandType)
  162. {
  163. object result = 0;
  164. if (string.IsNullOrEmpty(_conn))
  165. throw new ArgumentNullException("Connection string is missing.");
  166. if (string.IsNullOrEmpty(commandText))
  167. throw new ArgumentNullException("commandText");
  168. SQLiteCommand cmd = new SQLiteCommand();
  169. using (SQLiteConnection con = new SQLiteConnection(_conn))
  170. {
  171. SQLiteTransaction trans = null;
  172. PrepareCommand(cmd, con, ref trans, true, commandType, commandText);
  173. try
  174. {
  175. result = cmd.ExecuteScalar();
  176. trans.Commit();
  177. }
  178. catch (Exception ex)
  179. {
  180. trans.Rollback();
  181. throw ex;
  182. }
  183. }
  184. return result;
  185. }
  186.  
  187. /// <summary>
  188. /// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
  189. /// </summary>
  190. /// <param name="connectionString">连接字符串</param>
  191. /// <param name="commandText">执行语句或存储过程名</param>
  192. /// <param name="commandType">执行类型</param>
  193. /// <param name="cmdParms">SQL参数对象</param>
  194. /// <returns>查询所得的第1行第1列数据</returns>
  195. public object ExecuteScalar(string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
  196. {
  197. object result = 0;
  198. if (string.IsNullOrEmpty(_conn))
  199. throw new ArgumentNullException("Connection string is missing.");
  200. if (string.IsNullOrEmpty(commandText))
  201. throw new ArgumentNullException("commandText");
  202.  
  203. SQLiteCommand cmd = new SQLiteCommand();
  204. using (SQLiteConnection con = new SQLiteConnection(_conn))
  205. {
  206. SQLiteTransaction trans = null;
  207. PrepareCommand(cmd, con, ref trans, true, commandType, commandText);
  208. try
  209. {
  210. result = cmd.ExecuteScalar();
  211. trans.Commit();
  212. }
  213. catch (Exception ex)
  214. {
  215. trans.Rollback();
  216. throw ex;
  217. }
  218. }
  219. return result;
  220. }
  221. #endregion
  222.  
  223. #region ExecuteReader
  224. /// <summary>
  225. /// 执行数据库查询,返回SqlDataReader对象
  226. /// </summary>
  227. /// <param name="connectionString">连接字符串</param>
  228. /// <param name="cmd">SqlCommand对象</param>
  229. /// <returns>SqlDataReader对象</returns>
  230. public DbDataReader ExecuteReader(SQLiteCommand cmd)
  231. {
  232. DbDataReader reader = null;
  233. if (string.IsNullOrEmpty(_conn))
  234. throw new ArgumentNullException("Connection string is missing.");
  235.  
  236. SQLiteConnection con = new SQLiteConnection(_conn);
  237. SQLiteTransaction trans = null;
  238. PrepareCommand(cmd, con, ref trans, false, cmd.CommandType, cmd.CommandText);
  239. try
  240. {
  241. reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  242. }
  243. catch (Exception ex)
  244. {
  245. throw ex;
  246. }
  247. return reader;
  248. }
  249.  
  250. /// <summary>
  251. /// 执行数据库查询,返回SqlDataReader对象
  252. /// </summary>
  253. /// <param name="connectionString">连接字符串</param>
  254. /// <param name="commandText">执行语句或存储过程名</param>
  255. /// <param name="commandType">执行类型</param>
  256. /// <returns>SqlDataReader对象</returns>
  257. public DbDataReader ExecuteReader(string commandText, CommandType commandType)
  258. {
  259. DbDataReader reader = null;
  260. if (string.IsNullOrEmpty(_conn))
  261. throw new ArgumentNullException("Connection string is missing.");
  262. if (string.IsNullOrEmpty(commandText))
  263. throw new ArgumentNullException("commandText");
  264.  
  265. SQLiteConnection con = new SQLiteConnection(_conn);
  266. SQLiteCommand cmd = new SQLiteCommand();
  267. SQLiteTransaction trans = null;
  268. PrepareCommand(cmd, con, ref trans, false, commandType, commandText);
  269. try
  270. {
  271. reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  272. }
  273. catch (Exception ex)
  274. {
  275. throw ex;
  276. }
  277. return reader;
  278. }
  279.  
  280. /// <summary>
  281. /// 执行数据库查询,返回SqlDataReader对象
  282. /// </summary>
  283. /// <param name="connectionString">连接字符串</param>
  284. /// <param name="commandText">执行语句或存储过程名</param>
  285. /// <param name="commandType">执行类型</param>
  286. /// <param name="cmdParms">SQL参数对象</param>
  287. /// <returns>SqlDataReader对象</returns>
  288. public DbDataReader ExecuteReader(string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
  289. {
  290. DbDataReader reader = null;
  291. if (string.IsNullOrEmpty(_conn))
  292. throw new ArgumentNullException("Connection string is missing.");
  293. if (string.IsNullOrEmpty(commandText))
  294. throw new ArgumentNullException("commandText");
  295.  
  296. SQLiteConnection con = new SQLiteConnection(_conn);
  297. SQLiteCommand cmd = new SQLiteCommand();
  298. SQLiteTransaction trans = null;
  299. PrepareCommand(cmd, con, ref trans, false, commandType, commandText, cmdParms);
  300. try
  301. {
  302. reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  303. }
  304. catch (Exception ex)
  305. {
  306. throw ex;
  307. }
  308. return reader;
  309. }
  310. #endregion
  311.  
  312. #region ExecuteDataSet
  313. /// <summary>
  314. /// 执行数据库查询,返回DataSet对象
  315. /// </summary>
  316. /// <param name="connectionString">连接字符串</param>
  317. /// <param name="cmd">SqlCommand对象</param>
  318. /// <returns>DataSet对象</returns>
  319. public DataSet ExecuteDataSet(SQLiteCommand cmd)
  320. {
  321. DataSet ds = new DataSet();
  322. SQLiteConnection con = new SQLiteConnection(_conn);
  323. SQLiteTransaction trans = null;
  324. PrepareCommand(cmd, con, ref trans, false, cmd.CommandType, cmd.CommandText);
  325. try
  326. {
  327. SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
  328. sda.Fill(ds);
  329. }
  330. catch (Exception ex)
  331. {
  332. throw ex;
  333. }
  334. finally
  335. {
  336. if (cmd.Connection != null)
  337. {
  338. if (cmd.Connection.State == ConnectionState.Open)
  339. {
  340. cmd.Connection.Close();
  341. }
  342. }
  343. }
  344. return ds;
  345. }
  346.  
  347. /// <summary>
  348. /// 执行数据库查询,返回DataSet对象
  349. /// </summary>
  350. /// <param name="connectionString">连接字符串</param>
  351. /// <param name="commandText">执行语句或存储过程名</param>
  352. /// <param name="commandType">执行类型</param>
  353. /// <returns>DataSet对象</returns>
  354. public DataSet ExecuteDataSet(string commandText, CommandType commandType)
  355. {
  356. if (string.IsNullOrEmpty(_conn))
  357. throw new ArgumentNullException("Connection string is missing.");
  358. if (string.IsNullOrEmpty(commandText))
  359. throw new ArgumentNullException("commandText");
  360. DataSet ds = new DataSet();
  361. SQLiteConnection con = new SQLiteConnection(_conn);
  362. SQLiteCommand cmd = new SQLiteCommand();
  363. SQLiteTransaction trans = null;
  364. PrepareCommand(cmd, con, ref trans, false, commandType, commandText);
  365. try
  366. {
  367. SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
  368. sda.Fill(ds);
  369. }
  370. catch (Exception ex)
  371. {
  372. throw ex;
  373. }
  374. finally
  375. {
  376. if (con != null)
  377. {
  378. if (con.State == ConnectionState.Open)
  379. {
  380. con.Close();
  381. }
  382. }
  383. }
  384. return ds;
  385. }
  386.  
  387. /// <summary>
  388. /// 执行数据库查询,返回DataSet对象
  389. /// </summary>
  390. /// <param name="connectionString">连接字符串</param>
  391. /// <param name="commandText">执行语句或存储过程名</param>
  392. /// <param name="commandType">执行类型</param>
  393. /// <param name="cmdParms">SQL参数对象</param>
  394. /// <returns>DataSet对象</returns>
  395. public DataSet ExecuteDataSet(string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
  396. {
  397. if (string.IsNullOrEmpty(_conn))
  398. throw new ArgumentNullException("Connection string is missing.");
  399. if (string.IsNullOrEmpty(commandText))
  400. throw new ArgumentNullException("commandText");
  401. DataSet ds = new DataSet();
  402. SQLiteConnection con = null;
  403. SQLiteCommand cmd = new SQLiteCommand();
  404. SQLiteTransaction trans = null;
  405. try
  406. {
  407. con = new SQLiteConnection(_conn);
  408. PrepareCommand(cmd, con, ref trans, false, commandType, commandText, cmdParms);
  409. SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
  410. sda.Fill(ds);
  411. }
  412. catch (Exception ex)
  413. {
  414. throw ex;
  415. }
  416. finally
  417. {
  418. if (con != null)
  419. {
  420. if (con.State == ConnectionState.Open)
  421. {
  422. con.Close();
  423. }
  424. }
  425. }
  426. return ds;
  427. }
  428. #endregion
  429.  
  430. /// <summary>
  431. /// 通用分页查询方法
  432. /// </summary>
  433. /// <param name="connString">连接字符串</param>
  434. /// <param name="tableName">表名</param>
  435. /// <param name="strColumns">查询字段名</param>
  436. /// <param name="strWhere">where条件</param>
  437. /// <param name="strOrder">排序条件</param>
  438. /// <param name="pageSize">每页数据数量</param>
  439. /// <param name="currentIndex">当前页数</param>
  440. /// <param name="recordOut">数据总量</param>
  441. /// <returns>DataTable数据表</returns>
  442. public DataTable SelectPaging(string tableName, string strColumns, string strWhere, string strOrder, int pageSize, int currentIndex, out int recordOut)
  443. {
  444. DataTable dt = new DataTable();
  445. //查询总数
  446. string countSql = "select count(*) from " + tableName + " where {0}";
  447. countSql = String.Format(countSql, strWhere);
  448. recordOut = Convert.ToInt32(ExecuteScalar(countSql, CommandType.Text));
  449. //分页
  450. string pagingTemplate = "select {0} from {1} where {2} order by {3} limit {4} offset {5} ";
  451. int offsetCount = (currentIndex - 1) * pageSize;
  452. string commandText = String.Format(pagingTemplate, strColumns, tableName, strWhere, strOrder, pageSize.ToString(), offsetCount.ToString());
  453. using (DbDataReader reader = ExecuteReader(commandText, CommandType.Text))
  454. {
  455. if (reader != null)
  456. {
  457. dt.Load(reader);
  458. }
  459. }
  460. return dt;
  461. }
  462.  
  463. /// <summary>
  464. /// 预处理Command对象,数据库链接,事务,需要执行的对象,参数等的初始化
  465. /// </summary>
  466. /// <param name="cmd">Command对象</param>
  467. /// <param name="conn">Connection对象</param>
  468. /// <param name="trans">Transcation对象</param>
  469. /// <param name="useTrans">是否使用事务</param>
  470. /// <param name="cmdType">SQL字符串执行类型</param>
  471. /// <param name="cmdText">SQL Text</param>
  472. /// <param name="cmdParms">SQLiteParameters to use in the command</param>
  473. private void PrepareCommand(SQLiteCommand cmd, SQLiteConnection conn, ref SQLiteTransaction trans, bool useTrans, CommandType cmdType, string cmdText, params SQLiteParameter[] cmdParms)
  474. {
  475.  
  476. if (conn.State != ConnectionState.Open)
  477. conn.Open();
  478.  
  479. cmd.Connection = conn;
  480. cmd.CommandText = cmdText;
  481.  
  482. if (useTrans)
  483. {
  484. trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
  485. cmd.Transaction = trans;
  486. }
  487.  
  488. cmd.CommandType = cmdType;
  489.  
  490. if (cmdParms != null)
  491. {
  492. foreach (SQLiteParameter parm in cmdParms)
  493. cmd.Parameters.Add(parm);
  494. }
  495. }
  496. }
  497. }

asp.net中配置使用Sqlite轻型数据库的更多相关文章

  1. ASP.NET Core 配置 EF SQLite 支持 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core 配置 EF SQLite 支持 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 配置 EF SQLite 支持 上一章节我有提 ...

  2. SpringBoot中配置起动时的数据库初始化角本

    一.简介 我们使用SpringBoot + JPA时,需要程序在启动时执行数据表的初始化或者数据库记录的初始化.一般数据表的初始化可以通过在Spring Boot的application.proper ...

  3. ASP.NET中配置应用程序

    1.   配置文件简介 1.1 分类 1.2关系 Machine.Config和Web.Config都是设置应用程序的配置信息,它们按照类似于继承的关系对应用程序起作用. Machine.Config ...

  4. 在Windows10系统中配置和运行MongoDB数据库,linux开启mongdb

    参考链接:http://jingyan.baidu.com/article/11c17a2c03081ef446e39d02.html linux中开启mongodb服务: 1.  进入到/data/ ...

  5. asp.netMVC中配置automap

    第一.新建类库,以解决方案名XXX为例,建立子类库名为  XXX.AutoMapper. 第二. XXX.AutoMapper类库中,添加对automap的引用. 第三.创建映射文件类 ModelPr ...

  6. 利用Advanced Installer将asp.netMVC连同IIS服务和mysql数据库一块打包成exe安装包

    因为业务需要,项目中需要把asp.netmvc项目打包成exe安装程序给客户,让客户直接可以点下一步下一步安装部署web程序,并且同时要将IIS服务和mysql一同安装到服务器上,因为客户的电脑可能是 ...

  7. ASP.NET中的配置文件

    ASP.NET中的配置文件 原创 2014年10月13日 08:15:27 1199   在机房收费系统的时候曾经应用过配置文件,当时也就那么一用对配置文件了解的不是很透彻,下面就来总结一下有关配置文 ...

  8. ASP.NET中后台数据和前台控件的绑定

    关于ASP.NET中后台数据库和前台的数据控件的绑定问题 最近一直在学习个知识点,自己创建了SQL Server数据库表,想在ASP.NET中连接数据库,并把数据库中的数据显示在前台,注意,这里的数据 ...

  9. 在Spring中配置SQL server 2000

    前言 Lz主要目的是在Spring中配置SQL server 2000数据库,但实现目的的过程中参差着许多SQL server 2000的知识,也包罗在本文记载下来!(Lz为什么要去搞sql serv ...

随机推荐

  1. OpenSSL中的大数接口与基于其的自用RSA加密接口设计

    本文记录了初次接触OpenSSL中的大数模块,重温了RSA加密流程,使用OpenSSL的接口包装成自用RSA加密接口,并且利用自己的接口演示了Alice与Bob通过RSA加密进行通讯的一个示例. 概览 ...

  2. linux下文件和目录

    (1)普通文件(regular file):这是最常用的文件类型,这种文件包含了某种形式的数据,文件内容的解释由处理该文件的应用程序进行. (2)目录文件(directory file):这种文件包含 ...

  3. 【★】KMP算法完整教程

    KMP算法完整教程 全称:                               Knuth_Morris_Pratt Algorithm(KMP算法) 类型:                 ...

  4. yyt

    红颜迤逦隔云梯, 相思萦系解花语. 我有相思千般意, 百磨不灭铭肝肠.

  5. 团队作业8——Beta 阶段冲刺6th day

    一.当天站立式会议 二.每个人的工作 (1)昨天已完成的工作(具体在表格中) 完善订单功能 (2)今天计划完成的工作(具体如下) 完善支付功能 (3) 工作中遇到的困难(在表格中) 成员 昨天已完成的 ...

  6. 第二次项目冲刺(Beta阶段)5.24

    1.提供当天站立式会议照片一张 会议内容: ①检查前一天的任务情况. ②制定新一轮的任务计划. 2.每个人的工作 (1)工作安排 队员 今日进展 明日安排 王婧 #63Web输出以文件名为标题 #63 ...

  7. 201521123022 《Java程序设计》 第九周学习总结

    1.本章学习总结 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 Q1.1 截图你的提交结果(出现学号) Q1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何 ...

  8. JS中的DOM对象及JS对document对像的操作

    DOM对象 windows:属性:opener(打开者) 方法:open().close(),setTimeout().setInterval()... location:属性:href 方法:rel ...

  9. ACM退役记&&回忆录

    ACM退役记 2017.9.19星期二,"九一八事变"八十六年后的第二天,永远记住这个日子,刚好是我报名ACM到现在,刚好满一年,而今天正是我注册杭州电子科技大学OJ的时间(就是这 ...

  10. Struts2第十篇【数据校验、代码方式、XML配置方式、错误信息返回样式】

    回顾以前的数据校验 使用一个FormBean对象来封装着web端来过来的数据 维护一个Map集合保存着错误信息-对各个字段进行逻辑判断 //表单提交过来的数据全都是String类型的,birthday ...