sql exception on ppc 2002

F

Fabio

Hi to the group

I'm running a vb .Net cf app on a pocket pc 2002.
I updated to .net cf sp2

Could anyone explain me why this function works in so strange way (look
at the comments)?

Public Function ExecuteCommand(ByVal sSql As String) As Boolean
Dim Conn As SqlServerCe.SqlCeConnection

Try
Conn = New SqlServerCe.SqlCeConnection(g_sDB_PALM) '<--
"Data Source = \Program Files\PocketAD\G_PDA.sdf;" it exists
Conn.Open() ' after this statement it jumps on next comment
row

Dim myCommand As SqlServerCe.SqlCeCommand = New
SqlServerCe.SqlCeCommand(sSql, Conn)

myCommand.ExecuteNonQuery()
Conn.Close()

Return True

Catch ex As InvalidOperationException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error:
ExecuteCommand")
Conn.Close()
Return False ' <-- I don't know why but it jump right
here !!!
Catch SQLe As SqlServerCe.SqlCeException
MsgBox(SQLe.Errors(0).Message,
MsgBoxStyle.Critical, "Error: ExecuteCommand")
Conn.Close()
Return False
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Critical, "Error:
ExecuteCommand")
Conn.Close()
Return False

End Try

End Function

If I soft reset the device and unplug from activesync everything goes
fine (if I run the built app directly from the device).
This kind of problem doesnt't occurr on PPC 2003.

Any Ideas?

Thanks a lot

Inviato da www.mynewsgate.net
 
W

William Ryan eMVP

Hi Fabio:

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Fabio said:
Hi to the group

I'm running a vb .Net cf app on a pocket pc 2002.
I updated to .net cf sp2

Could anyone explain me why this function works in so strange way (look
at the comments)?

Public Function ExecuteCommand(ByVal sSql As String) As Boolean
Dim Conn As SqlServerCe.SqlCeConnection

Try
Conn = New SqlServerCe.SqlCeConnection(g_sDB_PALM) '<--
"Data Source = \Program Files\PocketAD\G_PDA.sdf;" it exists
---------------
I"m not sure I understand, it's getting to this part then jumping over
everythign to the InvalidOperation code, but skipping the MessageBox too?
If the connection string has some unsupported properties or is bad, you'll
raise an ArgumentException - while InvalidOperation si getting caught I'd be
inclined to think the problem is there - however that wouldn't explain the
issue w/ it working after soft reset. That behavior looks like a bug that
may have been fixed but I'd need to look at the bug fixes before saying that
in any other context other than a guess.
Conn.Open() ' after this statement it jumps on next comment
row

Dim myCommand As SqlServerCe.SqlCeCommand = New
SqlServerCe.SqlCeCommand(sSql, Conn)

myCommand.ExecuteNonQuery()
Conn.Close()

Return True

Catch ex As InvalidOperationException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error:
ExecuteCommand")
Conn.Close()
Return False ' <-- I don't know why but it jump right
here !!!
Catch SQLe As SqlServerCe.SqlCeException
MsgBox(SQLe.Errors(0).Message,
MsgBoxStyle.Critical, "Error: ExecuteCommand")
Conn.Close()
Return False
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Critical, "Error:
ExecuteCommand")
Conn.Close()
Return False

End Try

End Function

-------------------
This isn't the problem, but why have all of the Conn.Close in each of the
exception handlers? That's what finally blocks are for and they are
'guaranteed' to execute so that's really the place to put the code,plus it
will save you a few lines of code. You will probably want to rethrow the
excpetion too depending on how your logic deals with the returning function
call. Another thing (just a suggesion), The ExcecuteNonQuery can fail for
many reasons as can the Connection.Open. I'd really trapt them separately
b/c they are fundamentally different issues.

I'll see if I can find that issue on the known issues - I seem to recall
seeing it before.
If I soft reset the device and unplug from activesync everything goes
fine (if I run the built app directly from the device).
This kind of problem doesnt't occurr on PPC 2003.

Will it work on the emulator?
 
F

Fabio

Hi William

I tried to run the same code on another ppc 2002.
It seems to work properly. I'm going to guess that the first one I tried
(the boss one)
was plenty of installed software including apps developed with eVB, .NET
cf apps, tomtom gps, bluetooh service, and other
staff he use for his businness...
I"m not sure I understand, it's getting to this part then jumping over
everythign to the InvalidOperation code, but skipping the MessageBox too?

Exactly. It sounds unbelievable to me as well!

This isn't the problem, but why have all of the Conn.Close in each of the
exception handlers? That's what finally blocks are for and they are
'guaranteed' to execute so that's really the place to put the code,plus it
will save you a few lines of code.

That'right. It was my mistake because I approached .NET world for few
months. Not enough experience ;-)
Will it work on the emulator?

I haven't tried yet. Maybe I'll do it today.

Thanks a lot for your suggestion

Inviato da www.mynewsgate.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top