SQLite连接在C#中不起作用 [英] SQLite Connection not working in C#

查看:367
本文介绍了SQLite连接在C#中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用处理SQLite数据库的C#应用​​程序,直到昨天工作正常,正在检索记录,

I was working with C# Application that manipulates a SQLite Database , Till yesterday It was working fine, It was retrieving records,

但是从昨晚开始,连接字符串返回了数据源= null

But since last night, Connection String returns Data Source = null

下面是测试代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;

namespace SQLiteTest
{
    public partial class Form1 : Form
    {
        //string connection_string = "Data Source=UrduDictionary";
        string connection_string = "Data Source=" + Environment.CurrentDirectory + "\\Test.sqlite";
        string query = "";
        private SQLiteConnection _connection;
        private SQLiteCommand _command;
        private SQLiteDataAdapter _adapter;
        DataSet local;
        public Form1()
        {
            InitializeComponent();
        }
    void Make_Connection()
    {
        _connection = new SQLiteConnection(connection_string);
    }
    private void button1_Click(object sender, EventArgs e)
    {                 
         Make_Connection();
    }

}

}

下面是在监视窗口中的调试过程中看到的图像。

Below is the image what have seen during Debug in Watch Window..


我正在使用的库 SQLite-1.0.66.0-setup.exe

我已经对创建的其他数据库进行了测试,但结果相同,任何机构都可以提供帮助?

I have tested with other Database created but same results, Any body can help?

推荐答案

我所做的:

private void button2_Click(object sender, EventArgs e)
{
    string dbPath = Path.Combine(Environment.CurrentDirectory, "UrduDictionary");
    string connString = string.Format("Data Source={0}", dbPath);

    using (SQLiteConnection conn = new SQLiteConnection(connString))
    {
        StringBuilder query = new StringBuilder();
        query.Append("SELECT * ");
        query.Append("FROM CATIGORY_TABLE ");

        using (SQLiteCommand cmd = new SQLiteCommand(query.ToString(), conn))
        {
            conn.Open();

            using (SQLiteDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    Console.WriteLine("{0} {1} {2}",
                        dr.GetValue(0),
                        dr.GetValue(1),
                        dr.GetValue(2));
                }
            }
        }
    }
}

这篇关于SQLite连接在C#中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆