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.


OpenDataSource(DataSourceName as String) as Boolean

The name of the data source to open.

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

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, ;
return toDatabase.OpenDataSource('System')


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


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


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


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