The issue of SQLCE being a single-user database really needs to be
addressed before developing your application as somewhere along the
way a second connection will be fired off or required causing
problems.
One way of getting around this is using a single connection object per
SQLCE database throughout the application.
Each time a piece of SQL is to be run create the command object, point
it to the connection, execute the SQL and then dispose the command
object.
Before executing the SQL, call a function that checks to see if the
connection is already in use. If it is then issue a message to the
user or if required loop until the connection is available.
The connection object does have various states so the following is
possible;
If DBconnection.State = ConnectionState.Executing Then
MessageBox.Show ("The database is busy - try again!")
End If
or
If DBconnection.State = ConnectionState.Closed Or DBconnection.State =
ConnectionState.Broken Then
Try
DBconnection.Close()
Catch ex As SqlCeException
DisplaySQLCEErrors(ex)
End Try
End If
This approach makes the application faster as the connection is always
available - therefore the wait involved in instantiating a new
connection each time a database interaction is required is not needed.
It also allows for multi-threading to be used in the .NETCF.
HTH
Garrett.
Rick Winscot said:
Zahid,
One thing to remember is that SQL CE is not a multiuser database... and will
only allow a single connection at a time. If you are using .NET take
advantage of the try block... if an exception is caught, you may be able to
step through other windows and kill the process that is using the database.
Rick Winscot
rickly@zyche dot com
Strider said:
If this comes from SQLCE, make sure that your database is not allready open
by another process. Check if SQLCE query is running at the background and is
connected to your database.
Zahid said:
Hi,
I got this error message:
" there is a file sharing violation. A different process
might be using the file [,,,,] "
What does this mean? How can I solve it?
Thanks in advance.