The GetMainDatabase method returns a Database object for the main database in the collection.

Syntax

GetMainDatabase() as Object

Parameters
None.

Return Value
A reference to the Database object for the main database.

Example
This example, taken from the OpenDataSource script example, opens a non-main database on the same server as the main database.

Visual FoxPro

lparameters toApplication as SQApplication, toDatabase as Database, tcDataSource
local loDatabase as Database, loDataSource as ODBCDataSource, ;
  loNewDataSource as ODBCDataSource
loDatabase               = toApplication.DataEngine.Databases.GetMainDatabase()
loDataSource             = loDatabase.CurrentDataSource
loNewDataSource          = toDatabase.DataSources.Item(1)
loNewDataSource.Server   = loDataSource.Server
loNewDataSource.UserName = loDataSource.UserName
loNewDataSource.Password = loDataSource.Password
loNewDataSource.Disconnect()
return loNewDataSource.Connect()

VBScript

function Main(Application, Database, DataSource)
dim MainDatabase, MainDataSource, NewDataSource
set MainDatabase       = Application.DataEngine.Databases.GetMainDatabase()
set MainDataSource     = MainDatabase.CurrentDataSource
set NewDataSource      = Database.DataSources.Item(1)
NewDataSource.Server   = MainDataSource.Server
NewDataSource.UserName = MainDataSource.UserName
NewDataSource.Password = MainDataSource.Password
NewDataSource.Disconnect()
Main = NewDataSource.Connect()
end function

JavaScript

function Main(Application, Database, DataSource) {
var MainDatabase, MainDataSource, NewDataSource ;
MainDatabase       = Application.DataEngine.Databases.GetMainDatabase() ;
MainDataSource     = MainDatabase.CurrentDataSource ;
NewDataSource      = Database.DataSources.Item(1) ;
NewDataSource.Server   = MainDataSource.Server ;
NewDataSource.UserName = MainDataSource.UserName ;
NewDataSource.Password = MainDataSource.Password ;
NewDataSource.Disconnect() ;
return NewDataSource.Connect() ;
}

See Also
Database Object | Databases Collection