Print Page | Close Window

I can not (because I have disconnected the LAN line) when I attempt to restore from the local cache

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=309
Printed Date: 24-May-2025 at 4:48pm


Topic: I can not (because I have disconnected the LAN line) when I attempt to restore from the local cache
Posted By: Customer
Subject: I can not (because I have disconnected the LAN line) when I attempt to restore from the local cache
Date Posted: 16-Jul-2007 at 3:58pm

I recently ran into a little head scratcher I'm hoping you can assist me with. I have a simple app and it allows you to get your data from a database or from an off-line cache thanks mostly to the demo/tutorial code of course... which for the most part functions as it should.

However if I attempt to connect (Using the ConnectDisconnect method from the tutorials and it turns out that I can not (because I have disconnected the LAN line) then when I attempt to restore from the local cache if fails with an unable to login exception. But if I execute the load from off-line without first attempting to connect - it works just fine.

Is there something in the PersistenceManager that might cause this or is there something in the RestoreStategy or MergeStrategy I'm missing? I've gone through the dev manual but can't seem to find my answer. Any ideas?




Replies:
Posted By: IdeaBlade
Date Posted: 16-Jul-2007 at 4:00pm

I found the problem.  I fixed it by making a change in the Disconnected Users Tutorial.  The RestoreEntitySet operation will attempt to merge the entities in the offline storage file with the PersistenceManager cache.  If it sees that PersistenceManager.IsConnected property is true, it will attempt to InitializeSchema from the backend database, and this will result in an exception because it cannot connect to the database.  I fixed the problem simply with a PersistenceManager.Disconnect before issuing the ResetoreEntitySet.  Here is the code:

 

private void LoadOffLine() {

      String path = Application.UserAppDataPath + "\\MyLocalData.bin";

      if (File.Exists(path)) {

        try {

          if (!mConnectedToDatabase)

            mPersMgr.Disconnect();

          mPersMgr.RestoreEntitySet(path);

          LoadData();

        }

        catch (Exception ex) {

          MessageBox.Show(ex.Message);

          File.Move(path, path + "\\" + DateTime.Now.ToString());

          MessageBox.Show("Local data file not found!");

        }

      }

    }

 

The reason the LoadOffLine operation worked immediately after opening the application is that the PersistenceManager was already disconnected in this case.




Print Page | Close Window