如何使用C#访问SQLite? [英] How can I access SQLite with C#?

查看:464
本文介绍了如何使用C#访问SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C#/ ASP.NET以编程方式连接到Sqlite数据库:

I'm trying to get connected to my Sqlite database programmatically using C#/ASP.NET:

string requete_sql = "SELECT * FROM USERS";
connStr = @"Data Source=C:\LocalFolder\FooBar.db;";
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr)) {
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(requete_sql,conn);
conn.Open();
cmd.ExecuteNonQuery();
}

但是(在conn.Open()行上)出现了一个异常, :

But an exception rises (on the conn.Open() line) telling that :

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

奇怪,因为我复制了在Web.config文件中找到的确切连接字符串。

Which is very odd because I copied the exact connection string found in the Web.config file.

如何避免这种异常?

PS:我的目标是仅以编程方式连接到没有web.config文件的数据库。

PS: My goal is to get connected only programmatically to the database without the web.config file.

谢谢,

注意。

推荐答案

您不能使用SQLProvider类连接到sqlite db。它们用于sql server。您需要使用 SQLite提供程序类。

You can not connect to sqlite db using SQLProvider classes. They are for sql server. You need to use SQLite provider classes.

这篇关于如何使用C#访问SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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