c# - SQLite 连接在 C# 中不起作用

标签 c# database sqlite connection-string

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

但是从昨晚开始,连接字符串返回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();
    }

}

下面是在监 window 口中调试时看到的图像..

我使用的库是 "SQLite-1.0.66.0-setup.exe"

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

最佳答案

这是我做的:

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));
                }
            }
        }
    }
}

关于c# - SQLite 连接在 C# 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26646399/

相关文章:

sqlite - 在 iOS 项目中管理 coredata/sqlite 数据库生命周期

c# - 为什么在 DLL 文件中启动的进程在使用控制台应用程序进行测试时有效,但在被另一个 DLL 文件调用时却无效?

c# - 在 WPF 应用程序中将数据从 C# 发送到 Javascript

java - 创建类路径资源中定义的名称为 'mongobee' 的 bean 时出错

database - Zend Framework 数据库初始化

php - 我应该使用某种数据库吗?

sqlite - Puppeteer 有 sqlite 吗?

c# - 为什么从 C# 4.0 开始使用的 COM 库需要大量使用动态类型?

c# - 如何在 winform 中禁用或隐藏 acrobat reader 书签面板?

ruby-on-rails-3 - Sqlite3 : Failed to build gem native extension