>

LoginTimeout Property

Applies To

DBEngine Object.

Description

Sets or returns the number of seconds before an error occurs when you attempt to log in to an ODBC database.

Settings and Return Values

The setting or return value is an Integer representing the number of seconds before a login timeout error occurs. The default LoginTimeout property setting is 20 seconds. When the LoginTimeout property is set to 0, no timeout occurs.

Remarks

When you're attempting to log into an ODBC database, such as SQL Server, the connection can fail as a result of network errors or because the server isn't running. Rather than waiting for the default 20 seconds to connect, you can specify how long the Microsoft Jet database engine waits before it produces an error. Logging on to the server happens implicitly as part of a number of different events, such as running a query on an external server database.

The default timeout value is determined by the current setting of the LoginTimeout property entry in the HKEY_LOCAL_MACHINE\SOFTWARE\Jet\3.0\ODBC key of the Windows Registry.

See Also

ODBCTimeout Property, QueryDef Object, QueryTimeout Property.

Example

This example sets the LoginTimeout property to 120 seconds and then creates and runs a query on a database on an ODBC server.


Dim dbsNorthwind As Database
Dim qdfCustomers As QueryDef, rstCustomers As Recordset
DBEngine.LoginTimeout = 120            ' Timeout in 2 minutes.
Set dbsNorthwind =  DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
                                    ' Create query.
Set qdfCustomers = dbsNorthwind.CreateQueryDef("All Cust", _
"SELECT * FROM Customers;") qdfCustomers.Connect = "ODBC;DSN=Human Resources; " & _
"DATABASE=HRSRVR; UID=Smith; PWD=Sesame" ' Log in to server and run query. Set rstCustomers = qdfCustomers.OpenRecordset()
Example (Microsoft Access)

The following example sets the LoginTimeout property to 120 seconds, then creates a query, and runs it on a database on an ODBC server.


Sub Login()
    Dim dbs As Database
    Dim qdf As QueryDef, rst As Recordset

    ' Set timeout to 120 seconds.
    DBEngine.LoginTimeout = 120
    ' Return Database variable that points to current database.
    Set dbs = CurrentDb
    ' Create query.
    Set qdf = dbs.CreateQueryDef("All Employees", _
"SELECT * FROM Employees;") qdf.Connect = "ODBC;DSN=Human Resources; " & _
"DATABASE=HRSRVR; UID=Smith; PWD=Sesame" ' Log in to server and run query. Set rst = qdf.OpenRecordset() End Sub