如何从 C# 连接到 SQLite 数据库文件?
我正在尝试使用 ac# 应用程序连接到 sqllite 数据库。我以前从未使用过 SQLLite。
var connectionString = @"data source='C:\TestData\StressData.s3db'";
connection = new SQLiteConnection(connectionString);
connection.Open();
当我尝试打开连接时,出现以下异常:
System.NotSupportedException: The given path's format is not supported.
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
我做错了什么?
谢谢..
尼克
更新:
我按照建议将“数据源”更改为“数据源”。现在我收到一个新错误:
更改此设置后,我收到一个新错误:System.ArgumentException:数据源不能为空。使用 :memory: 在 System.Data.SQLite.SQLiteConnection.Open() 打开内存数据库
还有更多建议吗?
I am trying to connect to a sqllite db from with a c# application. I have never worked with SQLLite before.
var connectionString = @"data source='C:\TestData\StressData.s3db'";
connection = new SQLiteConnection(connectionString);
connection.Open();
When i attempt to open the connection I get the following exception:
System.NotSupportedException: The given path's format is not supported.
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
What am I doing wrong?
Thanks..
Nick
Update:
I changed 'data source' to 'DataSource' as suggested to me. Now I receive a new error:
After changing this I get a new error: System.ArgumentException: Data Source cannot be empty. Use :memory: to open an in-memory database at System.Data.SQLite.SQLiteConnection.Open()
Any more suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明白了..
看起来“版本”属性不是可选的。有趣的是,.NET 提供程序并未在设计器属性窗口中显示这一点。
Got it..
Looks like the 'Version' attribute is not optional. Interesting that the .NET provider does not show this in the designer property window.
根据 此,
数据源
应该是DataSource
According to this,
data source
should beDataSource