DRZ400

Hi everyone,

I was wondering if anyone can help!

I'm writing an application on WM5 in VB and I'm having problems with SDF database files on the "Storage Card". I understand the concept of the connection being lost if the device hibernates BUT I can't find any information on how to reistablish the connection without getting the "Unspecified Error" of doom. (ExecuteResultSet: Connection property has not been initialized)

I know this can be fixed by moving the database files to main memory but they're 28Mb in total so they won't leave much room for anything else.

The code (which I borrowed from here) works fine until there's hibernation sleep/wake thingy and then it'll crash if it's run again!

----------------------------------------------------------------------------------------------------------------------------------------------------

Dim sql As String

Dim _conn As Data.SqlServerCe.SqlCeConnection

Dim cmd As New Data.SqlServerCe.SqlCeCommand()

Cursor.Current = Cursors.WaitCursor

_conn = New Data.SqlServerCe.SqlCeConnection("Data Source = \Storage Card\ZML\ZMLjumpers.sdf")

Try

_conn.Open()

Catch ex As Exception

MsgBox("error on open " & ex.Message.ToString)

End Try

sql = "SELECT * FROM expdt"

cmd.Connection = _conn

cmd.CommandText = sql

Cursor.Current = Cursors.WaitCursor

Dim rsCustomers As Data.SqlServerCe.SqlCeResultSet = cmd.ExecuteResultSet(Data.SqlServerCe.ResultSetOptions.Scrollable)

----------------------------------------------------------------------------------------------------------------------------------------------------

If anyone can shed any light on this it'd be greatly appreciated.

Cheers

Phil (UK)

PS ### Help for Noobs like me top tip ### To save a few people some hunting around ... if you want to convert a Access MDB database into a WM friendly format (SDF) lookup "Primeworks" on t'internet!! Works a treat!!



Re: Smart Devices VB and C# Projects SDF (storage card) database connection fails after hibernation VB

Ilya Tumanov

Most storage card drivers would invalidate all file handles after sleep/wake cycles. That means your connection is no longer valid and would error out. You can handle the error and reopen connection. Better solution is to make your application power aware which means you would close connection on sleep and reopen it on wake. There¡¯s an article on MSDN about ¡°power aware¡± applications (use quoted phrase as search keywords to find it).






Re: Smart Devices VB and C# Projects SDF (storage card) database connection fails after hibernation VB

DRZ400

Blimey ... ultra quick response!! Thanks!!

I've seen you mention before that making the program power aware will fix it, at which point everyone says "thankyou ... I've moved the database to main memory!" which makes me laugh!!

I'll have a look tomorrow as it's quite late... I'll post up my findings as others may find it useful.

Thanks for your help!!!!

Phil





Re: Smart Devices VB and C# Projects SDF (storage card) database connection fails after hibernation VB

DRZ400

Not good i'm afraid ... I'm not a full time programmer (ie not very good) and specialised in Business objects and VBA ... I don't know how to get round the "Unspecified Error" of doom. If anyone does figure out the "Holy grail" of hosting a SDF database on the storage card and reconnecting after a sleep/wake cycle in VB please post your ideas/thoughts/code here!!

Hosting in main memory does fix everything BUT my databases are too large to go down this route.

Best regards and thanks everyone for you help.

Phil (Not very good at this programming lark)





Re: Smart Devices VB and C# Projects SDF (storage card) database connection fails after hibernation VB

ScubaSteve20001

Do like Ilya said. When you catch this specific 'Unspecified Error' you can assume that you lost the connection of the database. So on the connection object, call the close method, and then create a new connection to the database. The best way to do this is to probably create a wrapper class for the sql ce database calls (like ExecuteReader, ExecuteScalar, ExecuteResultSet, etc) , that will automatically attempt to reopen the connection upon failure, this way you don't have to implement this reconnection stuff everywhere you have to access the database, just in your wrapper class.




Re: Smart Devices VB and C# Projects SDF (storage card) database connection fails after hibernation VB

DRZ400

Hi ... I'm VERY new to this and to be honest and just put it in the device memory instead! Maybe when i'm a bit better I'll try the "storage card" route again!

Thanks everyone for your help!! Bit wasted on me!

Cheers

Phil