用SqlCeConnection時,執行一段程式時就死當了,Hang在那裏,完全沒動作作
我也想不通,為何是在最後一行(19行),using{}的右括號
我用visual studio 2005開發Mobile 5的程式,用的是.
2.0, SQL CE3.1用SqlCeConnection時,執行一段程式時就死當了,Hang在那裏,完全沒動作作
我也想不通,為何是在最後一行(19行),using{}的右括號,
01 using (
02 SqlCeConnection l_DstConnection = new SqlCeConnection(GlobalClassCE.ConnectionString);//)
03 {
04 l_DstConnection.Open();
05 //Delete Command
06 SqlCeCommand l_Command_Delete = l_DstConnection.CreateCommand();
07 l_Command_Delete.CommandText = ls_SQL_Del;
08 //Start to insert
09 try
10 {
11 li_RowAffected = l_Command_Delete.ExecuteNonQuery();
12 }
13 catch (Exception ex)
14 {
15 MessageBox.Show(ex.ToString());
16 }
17 //return li_RowAffected;
18 // l_DstConnection.Dispose();
19 }
02 SqlCeConnection l_DstConnection = new SqlCeConnection(GlobalClassCE.ConnectionString);//)
03 {
04 l_DstConnection.Open();
05 //Delete Command
06 SqlCeCommand l_Command_Delete = l_DstConnection.CreateCommand();
07 l_Command_Delete.CommandText = ls_SQL_Del;
08 //Start to insert
09 try
10 {
11 li_RowAffected = l_Command_Delete.ExecuteNonQuery();
12 }
13 catch (Exception ex)
14 {
15 MessageBox.Show(ex.ToString());
16 }
17 //return li_RowAffected;
18 // l_DstConnection.Dispose();
19 }
後來拿掉using 在最後一行放l_DstConnection.Dispose();
,結果也是死當在l_DstConnection.Dispose(); 這行
後來在網頁上找到了一些資料,類似時況
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=2768009&SiteID=1
也不知原因為何,只好不用了。真是難搞啊。
Update PM16:55:
測試一下,用l_DstConnection.Close(); 也會死當...
Update 隔天AM 10:19
在Program的程式進入點Main()中寫法跟這個問題很大關係,
不能Run的寫法如下....(這種寫法在Window程式是ok的)
1 MenuForm menuForm = new MenuForm();
2 LoginForm l_LoginForm = new LoginForm();
3 if (l_LoginForm.ShowDialog() != DialogResult.Yes)
4 Application.Exit();
5
6 Application.Run(menuForm);
2 LoginForm l_LoginForm = new LoginForm();
3 if (l_LoginForm.ShowDialog() != DialogResult.Yes)
4 Application.Exit();
5
6 Application.Run(menuForm);
可以Run的寫法如下
MenuForm menuForm = new MenuForm();
//LoginForm l_LoginForm = new LoginForm();
//if (l_LoginForm.ShowDialog() != DialogResult.Yes)
//Application.Exit();
Application.Run(menuForm);
//LoginForm l_LoginForm = new LoginForm();
//if (l_LoginForm.ShowDialog() != DialogResult.Yes)
//Application.Exit();
Application.Run(menuForm);
Update 隔天PM 14:28
SqlCeDataAdapter.Fill(xxx); 用Fill也會死當,快被搞死了...決定改寫Program的程式進入點Main()
Update 隔天PM 15:52
問題解決了,果然是Program Class的Main()寫法,
改成這行就可了,從Login Form進入,menuForm進入點寫在LoginForm,
這個問題花了我3天的時間..xD
static class Program
{
[MTAThread]
static void Main()
{
LoginForm l_LoginForm = new LoginForm();
//從Login Form進入,MainMenu寫在LoginForm
Application.Run(l_LoginForm);
}
{
[MTAThread]
static void Main()
{
LoginForm l_LoginForm = new LoginForm();
//從Login Form進入,MainMenu寫在LoginForm
Application.Run(l_LoginForm);
}