SqlCeConnection closed after calling Open()

J

Jan Obrestad

I'm developing an appilcation using CF 1.0 and sqlce 2.0.

Lately I've gotten a strange error: The state of a connection remains
closed after calling Open()

Example:
Private Sub Connect()
'verify database is not blank

If conn Is Nothing Then
conn = New SqlCeConnection(Me.conStrForm)
End If

Try
conn.Open()
'Connection state is closed without throwing an exception.
Catch err As SqlServerCe.SqlCeException
'ErrorDisplay(err, "DBHelper.Connect")
Catch ex As Exception
'ErrorDisplay(ex, "DBHelper.Connect")
End Try
End Sub


This is running in a separate thread, but I'm using SyncLock to make
sure that only one thread writes to the database.

Does anyone have an idea of what is happening?


Jan
 
D

Darren Shaffer

Jan,

A couple of things:

1. it is likely that there is already a connection opened to the database,
so that
when you try to open a second one it closes immediately.

2. this is probably due to your threading model, but can't really help you
with
that because I haven't seen your code. my guess is that a previous thread
did
not close and dispose if a SqlCeConnection before another thread tries to
create one.

3. there is a newsgroup for SQL CE questions:
microsoft.public.sqlserver.ce

Regards,
Darren
--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 

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