INF: ODBC Messages on SQL Server Connections

ID: Q143339


The information in this article applies to:
  • Microsoft SQL Server version 6.0


SUMMARY

A successful connection to Microsoft SQL Server using the Microsoft SQL Server ODBC drivers will always return SQL_SUCCESS_WITH_INFO. If the application then calls SQLError() until it returns SQL_NO_DATA_FOUND there will be at least one 5703 and one or two 5701 messages.


MORE INFORMATION

SQL Server always issues at least two informational messages on a successful connection from any ODBC or DB-library client: A 5701 message, indicating which database on the server the user has been logged into, and a 5703 message, indicating what language the server is using. SQL Server's DB-library API and the Microsoft SQL Server ODBC driver always make these messages available on successful connects in case the application needs to use this information.

When an ODBC application calls SQLError() after getting SQL_SUCCESS_WITH_INFO, it should expect the following messages:

  1. A 5701 message showing SQL Server initially putting the user's context into the default database defined at the server for the login ID used in the connection.


  2. A 5703 message showing the language being used on the server.


  3. If either the ODBC datasource has a default database specified, or the application specified the DATABASE= keyword on SQLDriverConnect() or SQLBrowseConnect(), then there will be a second 5701 message showing the user's context being switched to the database requested.


For example, the following shows the messages returned on a successful connect by the SA login, which has its default database at the server defined as the master database, to a server running US English using an ODBC datasource which specifies pubs as the default database.

   Full Connect:

      szSqlState = "01000", *pfNativeError = 5701,
      szErrorMsg="[Microsoft][ODBC SQL Server Driver][SQL Server]
             Changed database context to 'master'."
      szSqlState = "01000", *pfNativeError = 5703,
      szErrorMsg="[Microsoft][ODBC SQL Server Driver][SQL Server]
             Changed language setting to 'us_english'."
      szSqlState = "01000", *pfNativeError = 5701,
      szErrorMsg="[Microsoft][ODBC SQL Server Driver][SQL Server]
             Changed database context to 'pubs'."

   Successfully connected to DSN 'ab60def'. 

Applications can simply ignore these 5701 and 5703 messages, they are purely informational. Applications cannot, however, ignore a return of SQL_SUCCESS_WITH_INFO return code on the SQLConnect(), SQLDriverConnect(), or SQLBrowseConnect(). This is because messages other than 5701s and 5703s may be returned that do require action. For example, if a driver connects to a SQL Server with outdated system stored procedures, the following will be one of the messages returned through SQLError():

   SqlState:   01000
   pfNative:   0
   szErrorMsg: "[Microsoft][ODBC SQL Server Driver]The ODBC
               catalog stored procedures installed on server
               ab421def are version 02.00.4127; version 06.00.0115
               or later is required to ensure proper operation.
               Please contact your system administrator." 

Applications need to code their error handling routines for SQL Server connections to call SQLError() until it returns SQL_NO_DATA_FOUND, and act on any messages other than the ones that return a pfNative code of 5701 or 5703.

Additional query words: 2.50.0121

Keywords : SSrvProg
Version : 2.50.0121 6.00
Platform : WINDOWS
Issue type :


Last Reviewed: March 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.