I’m working on an application written in C# in Compact Framework 2.0 for a Pocket PC. It is required that the application connects to the SQL CE database frequently. The sdf file is present in the PocketPC. Now I’m facing a problem now and then when the code tries to connect with the sdf file.
The code works fine for some time and then it suddenly starts throwing "There is a file sharing violation. A different process might be using the file."
I am disposing and closing the connection after each operation.
Please find the function code below which is being used for any database operation.
SqlCeConnection sqlCon = null;
sqlCon = ConnectionFactory.getInstance().getPrimDsConnection();
readCmd = sqlCon.CreateCommand();
dataReader = this.readCmd.ExecuteReader();
IList result = this.populateManyRows();
catch (SqlCeException sqlEx)
StringBuilder builder = new StringBuilder(
@"SqlCe Error in BaseReader.executeList() - ").Append(
throw new DataAccessException(sqlEx);
if( null != dataReader && ( !dataReader.IsClosed ))
if( null != readCmd) readCmd.Dispose();
if( null != sqlCon) sqlCon.Close();
catch (System.Exception ex)
I have also made sure that Query Analyzer is not running on my PDA.
Any help will be appreciated.