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() ;
}

C#

public static bool northwind_OpenDataSource(SFQApplication sfqApplication, 
  Database database, string dataSource)
{
  Database mainDatabase   = sfqApplication.DataEngine.Databases.GetMainDatabase();
  DataSource mainDataSource = mainDatabase.CurrentDataSource;
  DataSource newDataSource  = database.DataSources.Item(0);
  newDataSource.Server   = mainDataSource.Server;
  newDataSource.UserName = mainDataSource.UserName;
  newDataSource.Password = mainDataSource.Password;
  newDataSource.Disconnect() ;
  return newDataSource.Connect() ;
}

VB.NET

public shared function northwind_OpenDataSource(sfqApplication as SFQApplication,
  database as Database, dataSource as string) as Boolean
  dim mainDatabase as Database = sfqApplication.DataEngine.Databases.GetMainDatabase()
  dim mainDataSource as DataSource  = mainDatabase.CurrentDataSource
  dim newDataSource as DataSource  = database.DataSources.Item(0)
  newDataSource.Server   = mainDataSource.Server
  newDataSource.UserName = mainDataSource.UserName
  newDataSource.Password = mainDataSource.Password
  newDataSource.Disconnect()
  return newDataSource.Connect()
End Function

See also

Database Object | Databases Collection

© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic