locked
Access SqlCE-Database with Desktop Application Error RRS feed

  • Question

  • Hi All,

     

    im am using WindowsMobile 6.5 and SqlCE 3.5 to gather data on mobile device. As the data shall be stored centrally for all mobile devices i programmed a special synchronization framework as a desktop application. To connect the MobileDB I perform the following steps:

    1.Copy MobileDB in the working directory of the mobile application (via WMDC or a Cardreader containing the SD-Card used on the Mobile Device)

    2. Establish a DB-Connection using SqlCeConnection from System.Data.SqlServerCe

    Here in some scenarios but not always I or my users get an Errormessage that the DBConnection couldn´t be established because "another process" is using the DB. As i copied the DB directly before and only access the new file I wonder which process this could be. My users use XP, Vista and Windows7 as their operatingsystem. Their seems to be now way to access the data with the desktop application.

    Anyone can help?

     

    Regards,

    Tobias

    Saturday, September 25, 2010 11:25 AM

All replies

  • Hi Tobias,

    Could you show SqlCeConnection connection string, does it target to working directory of the mobile application? I suggest you reset the device, if the issue still is, it should desktop application use it, here we need restart PC to check it again.

     

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Tuesday, September 28, 2010 7:54 AM
  • Hi,

    Are you not closing the dbconnection after finishing your task. Some times in our code we forget to close the connection. That might be the reason. There may be chance to get this kind of error If you are attempting to open it with out closing.

    Regards,

    Malleswar

     

    Tuesday, September 28, 2010 11:20 AM
  • Hi Tobias,,

    If you still can't solve it, please feel free to unmark it and we can still discuss it in the thread.

     

    Best regards,
    Guang-Ming Bian - MSFT

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Friday, October 1, 2010 3:14 AM
  • Hi Guang-Ming and all others,

     

    the error still occurs in certain scenarios. To establish a connection I use a class named "Serializer" which is part of a specialised ORM-Tool.

    using System.Data.SqlServerCe;
    using System.Data.Common;
    using System.Windows.Forms;
    using System;
    
    namespace UBT.AI4.Bio.DivMobi.DatabaseConnector.Serializer
    {
      public class MS_SqlCeSerializer : Serializer
      {
        private string _dbPath;
    
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlCeSerializer"/> class.
        /// </summary>
        public MS_SqlCeSerializer(string dbPath) : base()
        {
          _dbPath = dbPath;
        }
    
        public override DbConnection CreateConnection()
        {
          
          string connection_string = "Data Source=\"" + _dbPath + "\";Max Database Size=128;Default Lock Escalation=100;";
          SqlCeConnection c=null;
          try
          {
            c = new SqlCeConnection(connection_string);
          }
          catch (Exception ex)
          {
            MessageBox.Show(ex.Message);
          }
          
          return c;
    
        }
      }
    }
    

    The way to establish a CE connection was suggested to be the standard way by several forums and works on my applicazion on the mobile device and also sometimes at the desktop application.

    The standard way to access the DB is to shutdown the mobile device and put the SD-card into a card-reader, wheras also the option to access the db via WMDC(with Rapi) exists. Hence, I don´t think that there is still an open connection.

    Question 1: It is also possible to copy the DB via WMDC without Rapi--which would be the most favorable way for me, but this results in an "unauthorized access vialotion". Does anbody know why?.

    From there the db is copied in the working directory of the desktop application. Older db-versions are overwritten in this step. This fails sometimes--which causes the Error. Hence, it seems at this point more than a user rights issue than a DBConnection issue.

    Question 2: How can I guarantee that older db´s are overwritten?

     

    Thanks for Your help,

     

    Tobias

    Tuesday, October 5, 2010 6:36 PM