简体   繁体   English

如何在C#中使用sqlite连接数据库

[英]How to connect to the database using sqlite in C#

I'm creating a program using C# and sqlite. 我正在使用C#和sqlite创建一个程序。

I need to connect my database, which is located on private server. 我需要连接位于专用服务器上的数据库。 How can I do it? 我该怎么做?

I already wrote some code to connect to my database on local system, but it's not what I want. 我已经写了一些代码来连接到本地系统上的数据库,但这不是我想要的。

And code, which I already wrote, can: connect to database and write some strings in DB and in the end - close the connection. 我已经编写的代码可以:连接到数据库并在DB中写入一些字符串,最后关闭连接。

This is my code: 这是我的代码:

 const string databaseName = @"C:\Users\ADmin\Desktop\selfie\db.db";
 SQLiteConnection connection =
 new SQLiteConnection(string.Format("Data Source={0};", databaseName));
 connection.Open();
 SQLiteCommand command = new SQLiteCommand("INSERT INTO 'qasu' ('question', 'answer', 'solution', 'uri') VALUES ('" + questionn + "','" + answwer + "','solution','uri');", connection);
 command.ExecuteNonQuery();
 connection.Close();

You need to put the database file on a fileshare on the server and make sure your client machine has access rights. 您需要将数据库文件放在服务器上的文件共享上,并确保客户端计算机具有访问权限。

const string databaseName = @"\\server\share\db.db";

Note however that it is not recommended to access an SQL Lite database from a network share, you might get locking issues according to the documentation . 但是请注意,不建议从网络共享访问SQL Lite数据库,根据文档可能会遇到锁定问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM