veryUrgent: SqlServerCe Problem

  • Thread starter Thread starter bob
  • Start date Start date
B

bob

Hi

I create a database at \\My Documents\\abc.sdf in my pocketPc. after pulling
one table from server using RDA.
I open a connection with my pocket pc database and get data. then i close
all open connection after getting data from pocketpc database.
when again i try to open the connection with my pocketpc database, it gives
me error

File is sharing by anyother process.

can any one help me to solve this problem.I m using C# as a front-end for my
application
 
Double check that you are calling Close() and Dispose() on all your
SqlCeConnection objects after you're done with them.
 
Why do we need to call Dispose as well?

Calling only close won't be enough?

Best Regards,
Y. SIvaram
 
Because the dispose method de-allocates the memory .... and you should
use it in your common practice

Regards,
Arif
 
Sorry, if this question is stupid. But I am really not sure.

I thought the .NET garbage collector will take care of the memory allocation
and as developers we do not need to worry about it.

Isn't it correct?

Best Regards,
Y. Sivaram
 
You are right but I think the garbage collector is activated after a
specific time and if you want to use the memory more efficiently, the
object must be disposed forcefully.

Regards,
Arif
 
Muhammad Arif said:
Because the dispose method de-allocates the memory .... and you should
use it in your common practice

Just to clarify, the Dispose method does *not* usually deallocate
memory. It frees up *unmanaged* resources, such as network connections,
native window handles etc.

(And closing a connection should actually be enough - it's just that
calling Dispose is usually easier, because then you can use a using
(...) construct.)
 
The answer is a little easier than you might think... If you are doing an
RDA pull... you already have an open connection into your database! SQL CE
is not a multiuser database - and as such will give you that error if you
try to open multiple connections. Either re-use your existing connection to
perform additional operations... or make sure your existing connections are
properly closed before trying to re-open new ones.

Rick Winscot
www.zyche.com
 
Rick, you may have hit on his problem. The RDA connection is opened and
closed during the Pull operation so the code bleow would work:
cn.Open
....
cn.Close
RDA.Pull
cn.Open

While code like the examples below will fail:
cn.Open
RDA.Pull // Errors with Sharing Violation
....

Thread (or process) 1:
cn.Open

Thread 2:
RDA.Pull // will fail if any other connections are open

The next version of Sql Server CE will allow multiple open connections.
Check http://microsoft.sitestream.com/PDC2003/MBL/MBL314_files/Default.htm
for details on V3.
 
Back
Top