Applies To DBEngine object, Workspace object.
Description
Sets or returns the number of seconds before an error occurs when you attempt to log on 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 on to an ODBC database, such as Microsoft 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 to wait before raising 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. You can use LoginTimeout on the DBEngine object in both Microsoft Jet and ODBCDirect workspaces. You can use LoginTimeout on the Workspace object only in ODBCDirect workspaces. Setting the property to –1 on a Workspace will default to the current setting of DBEngine.LoginTimeout. You can change this property in a Workspace at any time, and the new setting will take effect with the next Connection or Database object opened. The default value is determined by the ODBC driver. In a Microsoft Jet workspace, you can override the driver's default value by creating a new "ODBC" key in the Registry path \HKEY_LOCAL_MACHINE\SOFTWARE\Jet\3.5\, creating a LoginTimeout parameter in this key, and setting the value as desired.See Also ODBCTimeout property, QueryDef object, QueryTimeout property.
Example This example sets the LoginTimeout property of the DBEngine object to 120 seconds. It then opens three ODBCDirect workspaces and modifies their LoginTimeout properties from the default inherited from the DBEngine object.Sub LoginTimeoutX()
' Change the default LoginTimeout value.
DBEngine.LoginTimeout = 120
Dim wrkODBC1 As Workspace
Dim wrkODBC2 As Workspace
Dim wrkODBC3 As Workspace
Set wrkODBC1 = CreateWorkspace("", "admin", "", _
dbUseODBC)
Set wrkODBC2 = CreateWorkspace("", "admin", "", _
dbUseODBC)
Set wrkODBC3 = CreateWorkspace("", "admin", "", _
dbUseODBC)
' Change the LoginTimeout of the individual ODBCDirect
' workspaces for 60 seconds, the default time (120
' seconds), and no timeout.
wrkODBC1.LoginTimeout = 60
wrkODBC2.LoginTimeout = -1
wrkODBC2.LoginTimeout = 0
wrkODBC1.Close
wrkODBC2.Close
wrkODBC3.Close
End Sub
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 reference to current database.
Set dbs = CurrentDb
' Create new QueryDef object.
Set qdf = dbs.CreateQueryDef("All Employees", _
"SELECT * FROM Employees;")
qdf.Connect = "ODBC;DSN=Human Resources; " _
& "Database=HRSRVR; UID=Smith; PWD=Sesame"
' Log on to server and run query.
Set rst = qdf.OpenRecordset()
' Perform operations with recordset.
.
.
.
rst.Close
Set dbs = Nothing
End Sub