Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Changing to a different database path programmatically
Sat, May 5 2007 2:07 PMPermanent Link

"Royke"
Suppose a user wants to move an existing local database to a different path,
for example on a server. What we want to do is detect that the old path is
no longer there (easy), and ask the user to browse to the new path. Then the
next time the program opens it should go to the new path, no questions
asked.

I have not found a way to change the path to a database programatically.
Some older post says that adding a new database to the config file, with the
new path, is the only option. Not very smooth, but ok.

But the next time, the software will again go to the hardcoded original
database, not find its path, and again ask the user to browse to the new
path. Is my only option now to create some ini-file containing the new path,
and let that override the path for the original database? That is, open
program, which spots inifile, reads new path, queries the catalog for a
database to the new path, and uses that?

Roy


Sun, May 6 2007 8:27 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Royke


This makes a bit of sense about your other post. I'm making an assumption that what is hardcoded is the database name (if its the path you have a serious design problem), and also that this is a single user system, or at least whoever starts up first can get exclusive access.

What you need to do is

1. Detect that the data is no longer where it was left
2. DROP DATABASE straight away
3. Browse to the new location
4. CREATE DATABASE same name as the one you've dropped



Roy Lambert
Mon, May 7 2007 2:33 AMPermanent Link

Richard Harding
In my first and only ElevateDB application, I have placed the following code in the
DataModuleCreate method.

The Database name and the Configuration Location is stored in the registry.  The location
of the database is found from the qyConfiguration query.

=====================
 Reg := TRegistry.Create;
  try
     Reg.RootKey := HKEY_LOCAL_MACHINE;
     Reg.OpenKey('Software\WCK\RBTI', false);
     Database       := Reg.ReadString('Database');
     ConfigLocation := Reg.ReadString('ConfigLocation');
  finally
     Reg.CloseKey;
     FreeAndNil(Reg);
  end;

  if not DirectoryExists(ConfigLocation) then
  begin
     raise EDatabaseError.Create('Configuration Directory not present'#13#10 +
                                                'Check Configuration Location in Registry');
  end;

 EDBEngine1.ConfigPath     := ConfigLocation;
 EDBEngine1.TempTablesPath := ConfigLocation;

(* --------------------------------------------------------------------------- *)

 EDBEngine1.Active := True;
 EDBSession1.Connected := true;
 dbRBTI.Database := Database;
 dbRBTI.Connected := true;

 qyConfiguration.Active := False;
 qyConfiguration.DatabaseName := 'Configuration';
 qyConfiguration.SQL.Text := 'SELECT Path FROM Databases WHERE Name = ''' + Database + '''';
 qyConfiguration.Active := True;
 if (qyConfiguration.RecordCount = 1) then
 begin
   dbLocation := qyConfiguration.FieldByName('Path').AsString;
 end;

 if (dbLocation = '') then
     raise EDatabaseError.Create('The database ' + database + ' is not present');
========================

You could probably use:
   UPDATE Databases SET Path = <new path name>

to change the location of the database instead of using the SELECT to retrieve the location.

I have no idea if this is a sensible thing to do or not? ? ? ? ?


Richard Harding
Mon, May 7 2007 12:07 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Richard,

<< You could probably use:
   UPDATE Databases SET Path = <new path name>

to change the location of the database instead of using the SELECT to
retrieve the location. >>

No, most definitely not. Smiley You have to use the CREATE DATABASE/DROP
DATABASE statements to affect the Databases table in the Configuration
database.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image