无法打开我的SqliteConnection [英] Unable to get my SqliteConnection to open

查看:180
本文介绍了无法打开我的SqliteConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一些创建空白数据库的操作,然后运行命令来生成我的架构.据我所知,一切都已完成,但是由于某种原因,每次尝试连接时,我都会收到一条错误消息,提示参数C:\ Test \ test.db的格式无效"

这是我遇到问题的代码.

I need to do something where I create a blank database, and then run commands to generate my schema. I have everything worked out as far as I can tell, but for some reason every time I try to connect I get an error saying "Invalid format for parameter C:\Test\test.db"

Here''s the code where I get the problem.

<br />
<pre lang="cs">SQLiteConnection.CreateFile(filePath);<br />
               String connectionString = "Data Source=" + filePath+";";<br />
               using (var connection = new SQLiteConnection(filePath))<br />
               {<br />
                   connection.Open();</pre><br />
<br />
<br />


我已经在连接字符串属性中使用DataSource或Data Source进行了尝试.我还尝试了在结尾处添加或不添加分号. CreateFile有效,但随后我无法打开连接.每次都会引发异常.

有人可以帮我吗?


I have tried it with DataSource or Data Source in the connection string property. I also tried with and without that appended semicolon at the end. The CreateFile works, but then I can''t get my connection to open. It throws an exception every time.

Can anyone please help me?

推荐答案

您必须将connectionString传递给构造函数,而不是路径

使用(var connection = new SQLiteConnection( connectionString ))

-Robotex
You must pass connectionString to the constructor, not the path

using (var connection = new SQLiteConnection(connectionString))

-Robotex


这篇关于无法打开我的SqliteConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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