This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v20 R7
OPEN DATABASE

OPEN DATABASE 


 

OPEN DATABASE ( filePath ) 
Parameter Type   Description
filePath  String in File name (.4db, .4dc, .4dbase, .4dproject, .4dz, or .4dlink) or complete access path of database to open

Note   

The OPEN DATABASE command closes the current 4D database and opens on-the-fly the database defined by filePath. This command is useful for automatic testing purposes, to reopen a database automatically after a compilation, or to allow a merged 4D remote application to select the a database server to connect.

In the filePath parameter, pass the name or full access path of the database to be opened. You can use files having one of the following extensions:

  • .4db (interpreted structure file),
  • .4dc (compiled structure file),
  • .4dbase (macOS package),
  • .4dproject (project database file)
  • .4dz (deployment file for project databases)
  • .4dlink (shortcut file).

If you pass only a file name, this file must be placed at the same level as the structure file of the current database.

If the access path defines a valid database, 4D quits the database that is already open and then opens the specified database. In single-user mode, the On Exit database method of the database being closed and the On Startup database method (or the On Server Open Connection database method) of the database being opened are called successively.

Warning: Since this command causes the application to quit before re-opening with the specified database, it is usually not recommended to use it in the On Startup database method or in a method called by this database method. 

The command is executed in an asynchronous manner: after its call, 4D continues executing the rest of the method. Then, the application behaves as if the Quit command was selected in the File menu: open dialog boxes are cancelled, any open processes have 10 seconds to finish before being terminated, and so on.

If the target database file is not found or is invalid, a standard file system error is returned and 4D does nothing.

 OPEN DATABASE("C:\\databases\\Invoices\\Invoices.4db")

You want to select a server at startup from a single-user application. You could execute this code from a process launched by the On Startup database method:

 C_TEXT($xml)
 $xml:="<?xml version=\"1.0\" encoding=\"UTF-8\"?><database_shortcut is_remote=\"true\" server_database_name=\"{databaseName}\" server_path=\"{IP}\"/>"
 $databaseName:="myServer"
 $IP:="192.168.6.7:19813"
 
 If(Shift down)
    $IP:=Request("IP address to connect to "+$databaseName;$IP)
 Else
    ok:=1
 End if
 
 If(ok=1)
    $xml:=Replace string($xml;"{databaseName}";$databaseName)
    $xml:=Replace string($xml;"{IP}";$IP)
    C_OBJECT($link)
    $link:=Folder(fk user preferences folder).file("server.4dlink")
    $link.setText($xml)
    OPEN DATABASE($link.platformPath)
 Else
    QUIT 4D
 End if

 
PROPERTIES 

Product: 4D
Theme: 4D Environment
Number: 1321

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v14 R3

 
ARTICLE USAGE

4D Language Reference ( 4D v20 R7)