不支持关键字:'版本' [英] Keyword not supported: 'version'
问题描述
我有一个在 VS2010 中作为 WinForms 项目编写的项目.我不是在 VS2012 中将它作为 WPF 项目编写的.我有一个引用的 DLL (DailyReport
).DailyReport
内部是一个名为 GetUniqueDates()
的方法.它看起来像这样:
I've got this project that I wrote in VS2010 as a WinForms project. I'm not writing it in VS2012 as a WPF project. I have a referenced DLL (DailyReport
). Inside DailyReport
is a method called GetUniqueDates()
. It looks like this:
public List<string> GetUniquesDates()
{
var dates = new List<string>();
const string query = "SELECT date FROM hdd_local_data_v1_2";
try
{
// Exception here on the connection creation
using (var connection = new SqlConnection(ConnectionStringFile))
{
using (var command = new SqlCommand(query, connection))
{
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
for (var i = 0; i < reader.FieldCount; i++)
{
dates.Add(reader.GetValue(i).ToString());
}
}
}
}
}
}
catch (Exception ex)
{
Logger.Error(ex.Message);
}
dates.Sort();
return dates.Distinct().ToList();
}
ConnectionStringFile
在构造函数中设置,如下所示:
The ConnectionStringFile
is set in the constructor, and looks like this:
ConnectionStringFile = @"Data Source=C:\hdd_data\Rubicon.hdd;Version=3;New=False;Compress=True;";
现在,在我的 VS2010 WinForms 项目中,这种方法工作得很好.但是,在我的 VS2012 WPF 项目中,我遇到了上面提到的异常.例外是:
Now, in my VS2010 WinForms project, this method worked just fine. However, in my VS2012 WPF project, I get an exception where I noted above. And the exception is:
keyword not supported 'version'.
数据库是一个 SQLite 数据库.我试过删除 version
关键字,但是我得到了异常:
The database is a SQLite database. I've tried removing the version
keyword, but then I'd get the exception:
keyword not supported 'new'.
我的问题是:为什么连接可以在我的 WinForms 项目而不是我的 WPF 项目中工作?处理数据库连接时有什么变化吗?
My question is: Why would the connection work in my WinForms project and not my WPF project? Is there something that changed when dealing with database connections?
另外,请注意,这不是关于参数化查询等的问题.因此,如果可能,请对自己发表这些评论.谢谢.
Also, please note, this isn't a question about parameterized queries and the like. So, if possible, please those comments to yourself. Thank you.
推荐答案
我遇到的问题是因为我试图创建一个 SqlConnection
而不是 SQLiteConnection
.做出改变解决了我的问题.
The issue I was having was because I was trying to create a SqlConnection
instead of a SQLiteConnection
. Making that change solved my issue.
这篇关于不支持关键字:'版本'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!