index > SQL Server Everywhere Edition > Using the same connection in multiple threads -> native except...

Using the same connection in multiple threads -> native except...

I found a peculiar thing today while working with SQL Mobile in a multithreaded application (VS2005, application for Pocket PC 2003).

I created a class which has one SqlCeConnection object. Every time I call a function to insert/select/delete something from the local db, I open the connection, execute the query an then close the connection again.

But when I'm calling a function from the db class in thread 1 and in the meantime call a different function (from the same db class of course) in thread 2, things go wrong. Because when function 1 wants to close the connection, function 2 is still using the connection and it will crash my application with a native exception (0xC0000005: access violation).

I can see why the error is happening, but shouldn't there be a nice .NET handled exception instead of a native exception which grinds my app to a hold?

(A workaround I use now is to use multiple connection objects instead of one, but I thought I'd give this feedback anyway)

Tom v E

I thought I fixed it by using multiple connection objects, but as it turns out I still get the access violation error.

Is there anything special I have to set for using a SQL Mobile db in a multithreaded environment?

Tom v E

If you're using SQLCE V2 then you can only use one connection to the database period. I had to synclock my db access layer. so each call from each thread waits for the others to finish. Big Mess, luckily SQL Server 2005 Mobile allows multiple connections. If you're using VS2005 and writing to .NETV2 you may want to switch ot SQL Server 2005 mobile.

If you are already using that version, sorry unknown issue :)

Robert Brown

BadgerB

1) You should have a connection (SqlCeConnection) for each thread separately.

2) The error you are getting is general multi-threaded programming error. The same error you would get if you have a memory pointer between two threads. One thread is accessing it and while the other thread frees it. This is not a SQL Mobile DB problem.

3) What SQL Mobile operations you are trying to do.

Can you please elaborate your environment and operations in details. What does your app do?

Thanks,

Laxmi Narsimha Rao ORUGANTI, MSFT, SQL Mobile, Microsoft Corporation




Please hit "Yes", if my post answered your question(s). All postings are as-is and confer no rights.
Laxmi NRO MSFT
reply 4

You can use google to search for other answers

 

More Articles

• Windows Mobil ??SQL- Symbol MC70 Problem
• SQL 2005 Mobile vs .NET CF 2.0 SP1?
• SQL Server 2005 Mobile: problem with connection to database
• Test deploying WinForms app with SQL/e
• IIS error on New Subscription
• MDB to SDF
• Remote synchronise from PDA to SQL Server 2005
• SQL Server Everywhere OLE DB sample
• SQL server mobile deployment problem
• Views not working
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Replication with filter
• Cannot save English dates!
• An instance of the SQL Server Reconciler
• Corrupt SQLCE 2.0 Database File
• MSDE & SQL Server 2005 Mobile Server
• how to make Pocket PC synchronization se
• ResultSet in Avalon (WinFX-WPF-.net3.0)
• EDB record limits and EDB vs RAPI
• query performance issue of Sql server 20
• replication; what is: SqlCeReplication.S
• SQl Server CE database connection issue
• Not all subscriber types in New Subscrip
• What is SQL Everywhere?
• How to show data in a Label item?
• Sysem.Data.SqlServerCe.SyncStatus' is in

Hot Articles

• Using SqlCeEngine to verify/Restore a da
• Could not load file or assembly 'System.
• SQL 2005 Mobile loading 2003 Cabs
• SQL CE and SQL Server 2005
• SQL Mobile performance/size problems wit
• Merge Replication Without Merging Client
• Obtain sqlceresultset table schema with
• SSev and Enterprise Library
• Buffer size not specified error
• Funny problem (bug?) using MAX() on SQL
• File Size Limit
• How to create a SQL ev DB?
• DB_E_ROWSNOTRELEASED ADO2.81 Recodset-&
• My SQL application on Windows Mobile 5
• SqlServerCe.dll

Recommend Articles

• SqlCeConnection guidelines - keep it open?
• connecting to sql server from mobile dev
• VS2005/SQL Server 2005 Mobile subscribin
• Dates problem in SQL Server Evrywhere ed
• SDK for SQL ev?
• Can it be a bug in SQL CE?
• retrieving data from database...
• Return Top row from a ResultSet - SQL Se
• SCOPE_IDENTITY()
• HostName and ReinitializeSubscription
• Subscription Missing
• SQL Mobile and Vista
• Merge replication and SSL
• Newbie: Am I really using Everywhere?
• Setting Security on DB