Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#使用SQL Lite数据库部署以在其他PC上工作_C#_Wpf_Sqlite_Deployment - Fatal编程技术网

C#使用SQL Lite数据库部署以在其他PC上工作

C#使用SQL Lite数据库部署以在其他PC上工作,c#,wpf,sqlite,deployment,C#,Wpf,Sqlite,Deployment,我有一个WPF项目,其中我通过NuGet添加了SQLLite 我的主要目标是编写一个函数,如果数据库不存在,则生成数据库,然后将记录写入其中 它在我的电脑上运行良好,但在我部署应用程序并在其他电脑上运行后,它立即崩溃。 (我将*.db文件添加到解决方案中,但也没有帮助) (我的问题是它错过了另一台电脑上SQL Lite的*.dll文件) 我应该怎么做,使它在其他PC上也能工作 到目前为止,我的代码是: string relativePath = @"getstarted.db"; SQLiteC

我有一个WPF项目,其中我通过NuGet添加了SQLLite

我的主要目标是编写一个函数,如果数据库不存在,则生成数据库,然后将记录写入其中

它在我的电脑上运行良好,但在我部署应用程序并在其他电脑上运行后,它立即崩溃。 (我将*.db文件添加到解决方案中,但也没有帮助)


(我的问题是它错过了另一台电脑上SQL Lite的*.dll文件)

我应该怎么做,使它在其他PC上也能工作

到目前为止,我的代码是:

string relativePath = @"getstarted.db";
SQLiteConnection conn = new SQLiteConnection("Data Source=" + relativePath);
conn.Open();
using (SQLiteCommand mCmd = new SQLiteCommand("CREATE TABLE IF NOT EXISTS [Test Table] (id INTEGER PRIMARY KEY AUTOINCREMENT, 'username' TEXT, 'password' TEXT);", conn))
{
   mCmd.ExecuteNonQuery();
}
string Query = "insert into [Test Table](username, password) values('" + "testuser" + "','" + "testpassword" + "')";
SQLiteCommand insercommand = new SQLiteCommand(Query, conn);
insercommand.CommandType = CommandType.Text;
insercommand.ExecuteNonQuery();
[已解决]

基本上我改变了三件事

  • 我向解决方案中添加了x86和x64 SQLiteInterop.Dll-s

  • 我将连接字符串更改为

    字符串mDbPath=System.AppDomain.CurrentDomain.BaseDirectory+“getstarted.db”

  • 我将构造函数更改为

    SQLiteConnection conn=新的SQLiteConnection(“数据源=“+mDbPath,true”)


  • “(我的问题是它丢失了另一台电脑上SQL Lite的*.dll文件)”-如果你没有传输这些文件,你可能是对的。只是用你的exe复制它们。我复制了,但也没用。你想在哪里创建数据库?您不能只写入程序文件中的文件夹。使用appdata。您能更具体地说明我应该在appdata中做什么/更改什么吗?在打开数据库文件之前,您不是必须创建它吗:“SQLiteConnection.CreateFile(“getstarted.db”);”