1
我有這個項目,我在VS2010中寫作WinForms項目。我不是將它作爲WPF項目編寫在VS2012中。我有一個引用的DLL(DailyReport
)。 DailyReport
內部是一種名爲GetUniqueDates()
的方法。它看起來像這樣:不支持的關鍵字:'版本'
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
在構造函數中設置,看起來像這樣:
ConnectionStringFile = @"Data Source=C:\hdd_data\Rubicon.hdd;Version=3;New=False;Compress=True;";
現在,在我的VS2010的WinForms項目,這種方法效果很好。但是,在我的VS2012 WPF項目中,我發現上面提到的例外情況。並且例外是:
keyword not supported 'version'.
該數據庫是一個SQLite數據庫。我試圖消除version
關鍵字,但後來我得到異常:
keyword not supported 'new'.
我的問題是:爲什麼會在我的WinForms項目的連接工作,而不是我的WPF項目?處理數據庫連接時是否有更改?
此外,請注意,這不是關於參數化查詢等的問題。所以,如果可能的話,請把這些評論給你自己。謝謝。
看看這個鏈接:http://www.connectionstrings.com/sqlite特別是最後一個項目。 –
@MarkKram:正如我之前提到的那個發佈這個答案,然後刪除他的問題的人,我的數據庫位於我的連接字符串中列出的路徑中。根據該鏈接,「內存數據庫」部分,我有正確的字符串。 – MyCodeSucks
您是否需要使用實際的SQLite類來訪問SQLite內存數據庫?我很確定微軟的標準SqlConnection沒有關於如何連接到其中一個的線索...... =) –