| Stonefield Query SDK |
| Connect |
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
Connect() as Boolean
Parameters
None
Return Value
True if the connection was successfully made, False if not.
Example
This 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 = Application.DataEngine.Databases.GetMainDatabase() ;
var MainDataSource = MainDatabase.CurrentDataSource ;
var NewDataSource = Database.DataSources.Item(1) ;
NewDataSource.Server = MainDataSource.Server ;
NewDataSource.UserName = MainDataSource.UserName ;
NewDataSource.Password = MainDataSource.Password ;
NewDataSource.Disconnect() ;
return NewDataSource.Connect() ;
}This code calls the GetMainDatabase method of the Databases collection of the DataEngine object of the passed Application object to return a Database object containing properties for the main database. It then uses the CurrentDataSource property of the main database object to get a reference to the DataSource object for the current data source. The database that this is the script for has only one data source object in its DataSources collection (Stonefield Query sets this up automatically), so a reference to that object is put into the NewDataSource variable. Then the Server, UserName, and Password properties of that DataSource object are set to the appropriate values from the main database's current DataSource object. The data source's Disconnect method is then called to ensure any former connection is closed and the Connect method is called to connect to the data source.
See Also
Database Object | Disconnect | OpenDataSource | Select
| Last Updated: 02/05/2008 |