New Posts New Posts RSS Feed: I can not (because I have disconnected the LAN line) when I attempt to restore from the local cache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

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

 Post Reply Post Reply
Author
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Topic: I can not (because I have disconnected the LAN line) when I attempt to restore from the local cache
    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?

Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down