Automatic Service-Mode Error Logging

Added in Flex2SQL 18.1. Applies to Windows.

Service mode is useful for WebApp, Thriftly, Windows services, scheduled tasks, and other unattended applications. It prevents driver dialogs from waiting for a user who cannot see them and records relevant failures in the Windows Event Log.

In 18.1, service mode also automatically starts an error trace file when no trace is already active. This provides a diagnostic file without changing application code or turning on detailed tracing in advance. It helps investigate database-login, licensing, and other driver errors reported after trace initialization.

When the Automatic Log Is Created

At driver initialization, the automatic file is created when:

  • The application is running in service mode.

  • No trace is already active from startup configuration.

  • No nonempty TRACE_ON in mertech.ini selects an explicit trace.

The automatic trace uses errors-only level -1, circular mode, and flushing enabled. The circular size normally defaults to 500 MB; a startup TRACE_FILE_MAX_SIZE environment setting can supply a different positive size.

An explicitly configured trace takes precedence. For example, if you already configured a detailed trace, enabling service mode does not create a second errors-only file or change that trace into an errors-only log. Environment variables TRACE_LEVEL and TRACE_FLUSH can also override the automatic defaults; remove conflicting settings if you want the default behavior.

Where the File Goes

The default log is placed beside the running application executable. Its base filename includes the executable’s filename and a local-time timestamp:

<full-executable-path>-YYYYMMDD-HHMMSS.log

For example, an application running from C:\Apps\OrderEntry\WebApp.exe might create:

C:\Apps\OrderEntry\WebApp.exe-20261117-143000.log

Look in the application’s executable directory, not the driver DLL directory or the Windows Event Log folder. The driver can append an execution-count suffix when it distinguishes multiple executions; use the executable-name prefix to locate the matching file.

The process account must be allowed to write in that directory. If it cannot open the file, automatic file tracing will not start. For installations where the executable directory is read-only, configure TRACE_ON explicitly to a writable logging directory as shown in Circular Logging for Deployed Applications. Specify level -1, circular mode, a size, and flushing in that configuration.

Enabling Service Mode

Set the following in the application’s environment before it loads a driver:

SET MDS_DRVR_SVC_MODE=1

For a Windows service, configure its inherited environment and restart the service. The driver also detects service mode automatically when the process runs in Windows session 0 or on a non-interactive window station. Explicitly setting the variable avoids depending solely on detection.

No separate trace-enabling command is needed for the default automatic log. Service-mode detection and automatic trace creation happen during driver initialization; changing an environment variable after that is not a request to start a new automatic log.

Using the Log

The trace contains error/warning output, diagnostic headers, and some driver status messages, rather than the normal stream of database operations. Flushing helps make recent output available promptly after a failure. It does not turn the trace into a crash dump or record every application exception.

Use the file together with Windows Event Log entries for failed logins, license problems, and missing dependencies. The existing event-log registration instructions remain in Tracing & Logging. The new file supplements event logging; it does not replace it.

Collect the file matching the affected application and time of the incident. If errors alone do not explain the problem, temporarily enable a more detailed trace using Circular Logging for Deployed Applications.

Each automatically named file can wrap and overwrite older content. Separate starts can leave multiple timestamped files: the circular size limit does not impose a total limit on the directory. Archive needed logs and remove older files as part of normal deployment maintenance.