OpenFileDialog->DialogShow() 结果导致 SQLite 中出现错误

发布于 2024-09-28 19:36:23 字数 907 浏览 1 评论 0原文

我有一个使用 SQLite 访问数据库的程序。当我在执行 SQLite 调用之前打开 OpenFileDialog 或 SaveFileDialog

result = sqlite3_prepare_v2(databaseConnection,converted,10000,&stmt,&strptr);

并选择“取消”时,一切正常(结果 == SQLITE_OK),但是当我选择“打开”时,即使我不这样做如果不对对话框的返回文件执行任何操作,它就会中断 (result == SQLITE_ERROR)。您知道为什么会发生这种情况吗?

非常感谢您抽出时间!

编辑:这是我正在使用的代码:

OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->ShowDialog();
sqlite3_stmt * stmt;
const char * strptr;
sqlite3 * databaseConnection;

int result = sqlite3_open("virtualpatient_chat.db", &databaseConnection);

if (result != SQLITE_OK) return;
result = sqlite3_prepare_v2(databaseConnection,"SELECT * from mappings;",10000,&stmt,&strptr);

if (result != SQLITE_OK) return;

奇怪的是,它在我当前的项目中不起作用,但我将其复制并粘贴到一个全新的项目中,并且错误不会重复。现在我只是想找出周围代码中的问题可能是什么......

I have a program that accesses a database using SQLite. When I open a OpenFileDialog or a SaveFileDialog before I do the SQLite call:

result = sqlite3_prepare_v2(databaseConnection,converted,10000,&stmt,&strptr);

and choose "Cancel", everything works okay (result == SQLITE_OK) but when I choose "Open", even if I don't do anything with the dialog's return file, it breaks (result == SQLITE_ERROR). Do you have any idea why this might be happening?

Thanks so much for your time!

EDIT: Here is the code I am using:

OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->ShowDialog();
sqlite3_stmt * stmt;
const char * strptr;
sqlite3 * databaseConnection;

int result = sqlite3_open("virtualpatient_chat.db", &databaseConnection);

if (result != SQLITE_OK) return;
result = sqlite3_prepare_v2(databaseConnection,"SELECT * from mappings;",10000,&stmt,&strptr);

if (result != SQLITE_OK) return;

Strangely, it won't work in my current project but I copied and pasted it into a brand new project and the error doesn't repeat. Now I'm just trying to figure out what the problem in my surrounding code could be...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城烟雨 2024-10-05 19:36:23

没有希望从问题中诊断出问题的根源。只是一些指示。

首先将 OpenFileDialog 的 RestoreDirectory 设置为 True。这可确保单击“打开”不会更改程序的工作目录。如果这有效,那么查询中对当前目录存在相当神秘的依赖关系。

接下来要担心的是使用对话框时加载的 DLL。项目+属性,调试选项卡,勾选“启用非托管代码调试”。打开对话框时查看“输出”窗口,它显示了被注入的 DLL 的列表。这些是 shell 扩展,其中之一可能与 SQLite 冲突。除了破坏内存或使用 SQLite 本身之外,没有真正的线索知道这样的扩展可能会做什么。您可以使用 SysInternals 的 AutoRuns 实用程序暂时禁用 shell 扩展。从非 Microsoft 编写的开始。

There's no hope to diagnose the source of the problem from the question. Just some pointers.

Start by setting the OpenFileDialog's RestoreDirectory to True. This ensures that clicking Open doesn't change the program's working directory. If that works then there's a rather mysterious dependency on the current directory in the query.

Next thing to worry about are the DLLs that are getting loaded when you use the dialog. Project + Properties, Debug tab, tick "Enable unmanaged code debugging". Check out the Output window when you open the dialog, it shows a list of the DLLs getting injected. These are shell extensions, one of them might conflict with SQLite. No real clue what such an extension might do beyond maybe corrupting memory or using SQLite itself. You can temporarily disable shell extension with the SysInternals' AutoRuns utility. Start with the ones not written by Microsoft.

够钟 2024-10-05 19:36:23

我终于弄清楚如何解决它。在对话框的属性下,我必须将 RestoreDirectory 属性设置为 true。我不太确定如何修复它,除非以某种方式通过更改目录使 SQLite 无法找到我的数据库文件。

感谢您的帮助!

I finally figured out how to fix it. Under the Properties for my dialog box, I had to set the RestoreDirectory property to true. I'm not quite sure how that fixed it unless somehow by changing the directory it made SQLite not be able to find my database file.

Thanks for your help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文