Ayende @ Rahien

Unnatural acts on source code

SQL CE Issues, Part 2

Hopefully I'll get the same quick "you are an idiot, this is how it is done" that I got the first time I posted about it. Here is my current issue. Attempting to open SQL CE from multiple threads has locked it out. This has been the state of the system for ~6 hours.

I don't mind the locks, I do mind the fact that there seems to be no way to specify a timeout for that, so the app just sit there, waiting, waiting, waiting.

image

Comments

Rik Hemsley
04/08/2008 03:24 PM by
Rik Hemsley

Is it just me, or... is SQL Server CE supposed to be a 'single user' database?

Ayende Rahien
04/08/2008 03:25 PM by
Ayende Rahien

It is supposedly safe for multi threading...

Mark S. Rasmussen
04/08/2008 03:58 PM by
Mark S. Rasmussen

You might be able to use something like the method I used just recently for a normal SqlConnection, to specify a timeout:

http://improve.dk/blog/2008/03/10/controlling-sqlconnection-timeouts

Peter ritchie
04/08/2008 04:15 PM by
Peter ritchie

The docs for SqlCeConnection look at little disappointing:

"Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe."

-- http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection(VS.80).aspx

Mr_Simple
04/08/2008 04:28 PM by
Mr_Simple

I haven't tried it because I don't use CE, but doesn't specifying a timeout value in the connect string work as per SQL Server?

SqlCeConnection conn = new SqlCeConnection();

conn.ConnectionString = "Persist Security Info=False; Data Source = Northwind.sdf;" +

"Password = <password>; server=mySQLServer;Connect Timeout=30";
Ayende Rahien
04/08/2008 04:48 PM by
Ayende Rahien

You cannot share a SqlCeConnection between threads, but you can use a single DB from multiple threads

Ayende Rahien
04/08/2008 05:07 PM by
Ayende Rahien

Mr_Simple,

No, this is not supported in SQL CE.

Frans Bouma
04/08/2008 05:22 PM by
Frans Bouma

CE is a horrible database. No scalar queries in selects/where etc., a nasty bug in parameter binding in anonymous parametered queries (so you have to change code for CE 3.x separately), and less features than MS Access.

I'd abandone it a.s.a.p. if you have the chance and go for a .mdb or firebird embedded approach.

Yuri
04/08/2008 05:29 PM by
Yuri

Looks like setting up 'ssce: default lock timeout' property in connection string can help you.

see http://msdn2.microsoft.com/en-us/library/ms173385.aspx

Ayende Rahien
04/08/2008 06:06 PM by
Ayende Rahien

This is for a transaction. And the default is valid and good for me.

My issue is with opening the connection

Mr_Simple
04/08/2008 08:12 PM by
Mr_Simple

See if this helps any.

http://msdn2.microsoft.com/en-us/library/aa326335(VS.71).aspx

Ayende Rahien
04/08/2008 08:19 PM by
Ayende Rahien

Connect Timeout is not supported by Sql CE

Alex Simkin
04/08/2008 09:46 PM by
Alex Simkin

I got this:

SQL Server Compact timed out waiting for a lock. The default lock time is 2000ms for devices and 5000ms for desktops. The default lock timeout can be increased in the connection string using the ssce: default lock timeout property. [ Session id = 2,Thread id = 4700,Process id = 4296,Table name = Test,Conflict type = s lock (x blocks),Resource = TAB ]

So, timeouts are supported.

Ayende Rahien
04/08/2008 09:50 PM by
Ayende Rahien

Alex,

the situation above is showing a situation of them waiting for ~6 HOURS.

That is with the defaults, so it should have timed out after 4 seconds, it didn't

Alex Simkin
04/08/2008 09:53 PM by
Alex Simkin

Well... It did for me (how else could I get this message). Can you build 10 LOC test bed demonstrating this deadlock?

Mr_Simpl
04/08/2008 10:59 PM by
Mr_Simpl

http://msdn2.microsoft.com/en-us/library/aa326335(VS.71).aspx

So basically you are saying the Microsoft docs are wrong - correct?

Just trying to save the rest of us a little time here so we don't have to run down the same issue.

Ayende Rahien
04/08/2008 11:00 PM by
Ayende Rahien

Those docs are for 1.1, I am using the 2.0 version.

And yes, the observed behavior doesn't match the docs.

Mr_Simple
04/08/2008 11:51 PM by
Mr_Simple

One last question, again for the benefit of us all, but mostly me because I need things simple.

Your comment "the observed behavior" has intrigued me because I work with databases most of the time, and like most folks here have had the docs not match our personal observations from time to time.

Are you stating you have found official Microsoft documentation that the connection timeout property is not supported anymore, or is this something that your are just fighting on your box at the moment.

There is a very important distinction between Microsoft dropping support for this critical feature and you fighting the API on your box.

Just wondering.

Ayende Rahien
04/08/2008 11:57 PM by
Ayende Rahien

I mean that doing new SqlCeConnection("Database=test.sdf;Connect Timeout=30").Open() throws an exception, Connect Timeout not understood.

Simkin Alex
04/09/2008 12:08 AM by
Simkin Alex

Connection Timeout property is read-only and is equal to 0.

http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection.connectiontimeout.aspx

Mr_Simple
04/09/2008 12:36 AM by
Mr_Simple

Ah. Now the explanation of the failure is simple, but most of all clear.

Mr_Simple says thanks for sharing your pain on this issue.

Comments have been closed on this topic.