Shared SQLCECommand Object

  • Thread starter Thread starter Paul [Paradise Solutions]
  • Start date Start date
P

Paul [Paradise Solutions]

Hi All

This is in relation to my post on multiple DataAdapters, and is
cross-posted as both groups have relevence.

I have one class of shared functions, subs and variables (variables are
private). The idea is so that I have one class available to my whole
application without the need for multiple instances. All database calls
ensure connection object is closed in the Finally segment of my Try-Catches.
For those that have not read my other post I have been experiencing a
SQLCE data file sharing violation when updating tables (update on one
table works, update on next table doesn't).

What I was wondering if anyone could expand upon is:

If Class1 makes a call to SharedDataClass and uses 'AddOrderHeader'
(which then closes the database connection) and then Class2 makes a call
to SharedDataClass and uses 'AddOrderDetail' is there any chance that
the connection object is running in 2 threads (my code does not
programaticly use threading)?

I ask this as my Main form uses the DataAccessClass for retrieval and
this works. My order header class uses the DataAccessClass for insert
and select and this works. My OrderDetailClass uses the DataAccessClass
and consistently fails to insert/update (file share violation occurs
on ConnectionObject.Open, but no error occurs if I attempt to close it
{connection state is 'closed in command window}).

I used to use adapters, but believing they were the root of my issues
I've taken them out, but the problem remains.
As I've been working with databases in the past, I'm pretty sure my code
is good - especially as Brad Syputa[MS] didn't say there was anything
obviously wrong with it (see other post). This 'SHARED' angle is the
only one I have left.

Would appricate any help as with out full DB operation I'm in the myre...


Many thanks.


Paul
 
Hi All

Related Posts:
Shared SQLCECommand Object
Multiple DataAdapters and SQLCE File Sharing Issue

I'm not going to repeat the contents of the above posts because they're
too long. Basicly, it would seem, the use of a shared SQLCE Connection
object has a locking effect on the SQLCE datafile. This is not a
'Connection already open' issue as it would result in a different
exception message from:


ErrorParameters: {Length=3}
HResult: -2147467259
Message: "There is a file sharing violation. A different process
might be using the file. [,,,,,]"
NativeError: 25035
NumericErrorParameters: {Length=3}
Source: "Microsoft SQL Server 2000 Windows CE Edition"


After any usage of a shaerd connection object in one method and another
attepmt to use the same connection in another method, or creating a new
unshared connection (ensuring shared connection has been closed) results
in the above SQLCEException.

Is anyone else aware of such issues?


Many thanks


Paul
 
Paul said:
Related Posts:
Shared SQLCECommand Object
Multiple DataAdapters and SQLCE File Sharing Issue

I'm not going to repeat the contents of the above posts because they're
too long. Basicly, it would seem, the use of a shared SQLCE Connection
object has a locking effect on the SQLCE datafile. This is not a
'Connection already open' issue as it would result in a different
exception message from:


ErrorParameters: {Length=3}
HResult: -2147467259
Message: "There is a file sharing violation. A different process
might be using the file. [,,,,,]"
NativeError: 25035
NumericErrorParameters: {Length=3}
Source: "Microsoft SQL Server 2000 Windows CE Edition"


After any usage of a shaerd connection object in one method and another
attepmt to use the same connection in another method, or creating a new
unshared connection (ensuring shared connection has been closed) results
in the above SQLCEException.

Is anyone else aware of such issues?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

My guess is that you're not closing one connection, so creating a new
connection will give the exception listed above.
 
Jon said:
Paul said:
Related Posts:
Shared SQLCECommand Object
Multiple DataAdapters and SQLCE File Sharing Issue

I'm not going to repeat the contents of the above posts because they're
too long. Basicly, it would seem, the use of a shared SQLCE Connection
object has a locking effect on the SQLCE datafile. This is not a
'Connection already open' issue as it would result in a different
exception message from:


ErrorParameters: {Length=3}
HResult: -2147467259
Message: "There is a file sharing violation. A different process
might be using the file. [,,,,,]"
NativeError: 25035
NumericErrorParameters: {Length=3}
Source: "Microsoft SQL Server 2000 Windows CE Edition"


After any usage of a shaerd connection object in one method and another
attepmt to use the same connection in another method, or creating a new
unshared connection (ensuring shared connection has been closed) results
in the above SQLCEException.

Is anyone else aware of such issues?


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

My guess is that you're not closing one connection, so creating a new
connection will give the exception listed above.
I would agree with you, but in the post regarding multiple adapters I
did post code and, all-be-it on the surface, an MS bloke reckoned it was
correct. I also have the events captured from the connection object so
I can see the opens and closes (also in multi adapter post). If it's not
enough, I'll try to put something else together.


Many thanks


Paul
 
Paul said:
I would agree with you, but in the post regarding multiple adapters I
did post code and, all-be-it on the surface, an MS bloke reckoned it was
correct. I also have the events captured from the connection object so
I can see the opens and closes (also in multi adapter post). If it's not
enough, I'll try to put something else together.

I didn't see any real code in that post (only pseudo-code). Could you
post again, and make sure it's complete code we can run from scratch?
 
Jon said:
I didn't see any real code in that post (only pseudo-code). Could you
post again, and make sure it's complete code we can run from scratch?

23/06/2004, 10:29(BST)
Pleanty of code, the psudo and logs were about 1 post earlier. I will
however work on something full I can post, but that should give you an
idea. Wish I could put all my time into the sample but I also have to
get bits working, even if it is a severe work-around from what I was
planning.


Many thanks

Paul
 
Paul said:
23/06/2004, 10:29(BST)

I can't see any posts from you at that time - not in the group I'm
reading this in, anyway (the CF group). I'll have a look in the SQL CE
group...
Pleanty of code, the psudo and logs were about 1 post earlier. I will
however work on something full I can post, but that should give you an
idea. Wish I could put all my time into the sample but I also have to
get bits working, even if it is a severe work-around from what I was
planning.

I'm sure we'll be able to sort something out.
 
Hi there

I type this while wearing a large conical hat...

The very issue I was attempting to prevent via my 'shared class' had
unfortunately ~already~ occurred in one of my forms.

I would like to take this moment once again to say thanks to Brad Syputa
for:
1) looking into it for me
2) not saying "why on on earth you doing it like that??"

and also Jon Skeet, who bludgeoned me into writing a usable sample
(would not have found it otherwise).


Many thanks, and hope no-one burnt too much time lookng at it.


Paul

(I also write acceptance speaches..)
 
Back
Top