The OpenDataSource method opens the specified data source for the database. This method is usually called from the OpenDataSource script of a database to open a different data source. For example, suppose your application has two databases. The main one has multiple data sources available (such as Company 1 and Company 2) but the other database is a single system database. In that case, regardless of the data source selected by the user for the main database, the other database always opens the system database. So, the OpenDataSource script for the other database calls the database's OpenDataSource method, passing it a specific data source name.

If Stonefield Query fails to connect the data source, the ErrorMessage property contains the error message from the database engine. The error is also logged in the diagnostic file.

Syntax

OpenDataSource(DataSourceName as String) as Boolean

Parameters
DataSourceName
The name of the data source to open.

Return Value
True if the data source was opened, False if not.

Example
This example, called from the OpenDataSource script for a database, calls OpenDataSource to open a specific data source regardless of the data source name the user selected.

Visual FoxPro

lparameters toApplication as SQApplication, toDatabase as Database, ;
  tcDataSource
return toDatabase.OpenDataSource('System')

VBScript

function Main(Application, Database, DataSource)
Main = Database.OpenDataSource("System")
end function

JavaScript

function Main(Application, Database, DataSource) {
return Database.OpenDataSource('System') ;
}

C#

public static bool northwind_OpenDataSource(SFQApplication sfqApplication, 
  Database database, string dataSource)
{	
  return database.OpenDataSource("System");
}

VB.NET

public shared function northwind_OpenDataSource(sfqApplication as SFQApplication,
  database as Database, dataSource as string) as Boolean
  return database.OpenDataSource("System")
End Function

See also

Database Object | OpenDataSource

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