1
我在嘗試調試Visual Studio 2012中的Windows窗體應用程序時遇到問題。當我構建並運行該程序時,它將在執行完代碼段如下。它不會給我任何錯誤,或拋出任何異常。它只是死去,沒有給我任何我可以用來找出什麼是錯的。SQLiteConnection.Open()終止Windows窗體應用程序而不會拋出異常
這裏是它的時候我單步執行程序執行情況的類:
public class DBAdapter
{
protected static SQLiteConnection dbConnection = null;
protected static void initConnection() {
dbConnection = new SQLiteConnection(ConfigurationManager.ConnectionStrings["LocalData"].ConnectionString);
}
protected static void openConnection() {
if (dbConnection == null)
initConnection();
if (dbConnection.State == ConnectionState.Broken)
closeConnection();
else if (dbConnection.State == ConnectionState.Open)
return;
dbConnection.Open();//<-- Here is where it dies
}
protected static void closeConnection() {
if (dbConnection.State == ConnectionState.Closed)
return;
dbConnection.Close();
}
}
任何人都知道怎麼回事?
「沒有異常/錯誤」真的看起來......懷疑。 – user2864740 2014-10-07 20:59:50
看起來你對我的回答不滿意,我給你一個工作的例子,你的問題不是很好的結構,而且這意味着它的死亡。對於你在什麼樣的比賽中使用這種連接等等,我寫了更好的設計,在這種設計中,如果連接是打開或關閉的,或者無論什麼時候,你都不會進行檢查。就像我說的,你不滿意沒有問題,我正在刪除我的答案。祝你好運! – mybirthname 2014-10-07 21:39:37
@mybirthname你聽起來有點冒犯了。如果你是我很抱歉。我只是想澄清這個問題,並指出爲什麼你的答案不起作用,對於你或其他可能有**答案的人。你不應該因爲這個原因而刪除你的答案,即使這不是問題的實際答案。 – FireWingLead 2014-10-07 21:47:07