"There is a file sharing violation" - only I can't see how!

J

Jon Brunson

Firstly, sorry for the cross-post, but I don't know if this is a SQL
issue, or the Framework's fault, so I'm posting on both groups.

Secondly, sorry for the duplicate post - helps to press Return, not
Ctrl-Return when you want a new line...

Thirdly, my setup is CF 1.0-SP3, SqlCe 2.0, running on Windows CE 4.2
devices.


Anyway, my problem; I'm getting the following error reported in the
error log from a customer's site:

Code: 80004005
Msg : There is a file sharing violation. A different process might be
using the file.

Now, obviously the Database is in use, but from my code I cannot
envisage how. I have Sync Locks on a Locking object (Public Shared
ConnectionLocker As New Object) around whereever the Connection is used:

[VB.NET]
Public Shared Function GetByItemID(ByVal ItemID As Long) As DataRow
Try
SyncLock ConnectionLocker
Dim da As New SqlCeDataAdapter("SELECT * FROM
Procedure_Sections INNER JOIN Procedure_Items ON
Procedure_Sections.ItemID = Procedure_Items.ID WHERE
Procedure_Sections.ItemID = " + CStr(ItemID), Connection)
Dim dt As New DataTable
da.Fill(dt)

If dt.Rows.Count > 0 Then
Return dt.Rows(0)
Else
Throw New
Exception(Common.Resources.GetString("SectionNotFound"))
End If

End SyncLock
Catch ex As SqlCeException
Throw Common.ParsedSqlCeError(ex)
End Try
End Function
[/VB.NET]

And my connection itself is ONLY opened from ONE place, which is again,
Sync Locked

[VB.NET]
Friend Shared ReadOnly Property Connection() As SqlCeConnection
Get
Try
SyncLock ConnectionLocker

Static cnn As SqlCeConnection

If cnn Is Nothing Then _
cnn = New SqlCeConnection

If cnn.ConnectionString Is Nothing OrElse
cnn.ConnectionString.Trim().Length = 0 Then _
cnn.ConnectionString = "Data Source = 'Data.sdf'; Password =
'pieandchips'; Temp File Directory = '\Temp\PieAndChips\'"

If Not (IO.Directory.Exists(Data.TempFileDirectory)) Then _
IO.Directory.CreateDirectory(Data.TempFileDirectory)

If Not IO.File.Exists(Filename) Then
Dim e As SqlCeEngine
Try
' Cannot use cnn.ConnectionString, as the password
' gets stripped out when you read it back
e = New SqlCeEngine("Data Source = 'Data.sdf'; Password =
'pieandchips'")
e.CreateDatabase()

cnn.Open()

CreateAllTables()

Finally
If Not (e Is Nothing) Then e.Dispose()
End Try
End If

If cnn.State <> ConnectionState.Open Then _
cnn.Open()

Return cnn

End SyncLock
Catch ex As SqlCeException
Throw New
Exception(Common.Resources.GetString("ConnectionFailed") +
Common.ParseSqlCeError(ex), ex)
Catch ex As Exception
Throw New
Exception(Common.Resources.GetString("ConnectionFailed") + ex.ToString())
End Try
End Get
End Property
[/VB.NET]


Yes I have multiple threads accessing the Connection, yes every single
place that uses the Connection is Sync Locked until the method is
completely done with the Connection, yes I've double & triple checked
that this is the one and only place that my app opens the connection. I
am going mad, as this error is cropping up when they have been using the
app for a while (couple of hours) on the devices. The app cannot be
loaded more than once, and SqlCe Query Analyzer is not installed on the
devices, so I can't see another app having hold of the database.

Help me!
 

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