SQLite不能连接到另一台PC上的数据库

时间:2022-06-01 18:27:53

I have some issues with my SQLite database. When I'm making an app in WPF(VS2015) on my personal computer and I'm debugging a program, the whole database is working fine(no errors). But when I'm trying to run an .exe file on any other PC (I'm copying the whole debug folder with the database file in it) my application can't connect to database and it crashes.

我的SQLite数据库有一些问题。当我在我的个人电脑上制作一个WPF(VS2015)的应用程序,并且我正在调试一个程序时,整个数据库运行良好(没有错误)。但是,当我试图在任何其他PC上运行.exe文件时(我将整个调试文件夹复制到其中的数据库文件中),我的应用程序无法连接到数据库并崩溃。

            string dbConnection = @"Data Source=db2.db; Version=3;";
            SQLiteConnection sqliteCon = new SQLiteConnection(dbConnection);


        try
        {
            sqliteCon.Open();
            string Query = "select * from Haslo where Haslo = '" + this.passwordBox.Password + "' ";
            SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);

            createCommand.ExecuteNonQuery();
            SQLiteDataReader dr = createCommand.ExecuteReader();

It looks like it can't even connect to database file, beacause I left only this fragment and application stops here.

看起来它甚至不能连接到数据库文件,因为我只留下了这个片段,应用程序就停在这里。

string dbConnection = @"Data Source=db2.db; Version=3;";
SQLiteConnection sqliteCon = new SQLiteConnection(dbConnection);

I tried also to use "try and catch" here but nothing happend. After few seconds there is only MessageBox "Application stop running".

我也试着在这里使用“try and catch”,但是什么都没有发生。几秒钟后,只有MessageBox“应用程序停止运行”。

I also made a second database and this problem remained.

我还做了第二个数据库,这个问题仍然存在。

It's obvious that my PC have something that rest of computers haven not. I made database in mozilla addon "SQLite Menager". I'm new in proggraming so thanks for your patience. Any clues ?

很明显,我的电脑有其他电脑没有的东西。我在mozilla的addon“SQLite Menager”做了数据库。我是新手,谢谢你的耐心。有线索吗?

2 个解决方案

#1


2  

How did you install the SQLite DLLs on the first machine? If you installed them using the executable then they are probably in the GAC and that's why you can open it on the first machine but when you copy to the second machine, it doesn't have the DLLs.

你是如何在第一台机器上安装SQLite dll的?如果你用可执行文件安装它们那么它们可能在GAC中这就是为什么你可以在第一个机器上打开它但是当你复制到第二台机器时,它没有dll。

You can use the SQLite nuget package which will put all the necessary DLLs into your projects output folder so you can copy it to somewhere else.

您可以使用SQLite nuget包,它将把所有必要的dll放入项目输出文件夹,以便您可以将其复制到其他地方。

#2


0  

So the problem is that you can't get other computers to connect to the database on your computer? When I had this issue a while ago, it was because the firewall my computer was behind masked the ip so computers outside the firewall wouldn't recognize it.

问题是你不能让其他电脑连接到你电脑上的数据库?当我不久前遇到这个问题时,那是因为我的电脑在防火墙后屏蔽了ip,所以防火墙外的电脑无法识别它。

#1


2  

How did you install the SQLite DLLs on the first machine? If you installed them using the executable then they are probably in the GAC and that's why you can open it on the first machine but when you copy to the second machine, it doesn't have the DLLs.

你是如何在第一台机器上安装SQLite dll的?如果你用可执行文件安装它们那么它们可能在GAC中这就是为什么你可以在第一个机器上打开它但是当你复制到第二台机器时,它没有dll。

You can use the SQLite nuget package which will put all the necessary DLLs into your projects output folder so you can copy it to somewhere else.

您可以使用SQLite nuget包,它将把所有必要的dll放入项目输出文件夹,以便您可以将其复制到其他地方。

#2


0  

So the problem is that you can't get other computers to connect to the database on your computer? When I had this issue a while ago, it was because the firewall my computer was behind masked the ip so computers outside the firewall wouldn't recognize it.

问题是你不能让其他电脑连接到你电脑上的数据库?当我不久前遇到这个问题时,那是因为我的电脑在防火墙后屏蔽了ip,所以防火墙外的电脑无法识别它。