ACC1x: Queries Sent to Remote SQL Server Run Slowly

Last reviewed: May 28, 1997
Article ID: Q109815
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1

SYMPTOMS

A query sent to a remote SQL Server from Microsoft Access seems to run very slowly compared to other methods of querying SQL data.

CAUSE

This behavior can be due to either of the following causes:

  • A parameter used in the query is not explicitly defined, causing Microsoft Access to send the entire query to SQL Server.

    Microsoft Access automatically takes care of all implicit data type conversions internally, whether you are running a query against native Microsoft Access tables or attached tables. However, you will find that your remote queries run much slower than you expect when you force Microsoft Access to interpret query parameter data types, because it cannot be certain what implicit type conversions the remote server provides. As a result, Microsoft Access will not send the entire query to the remote server, but instead will locally process the parts of the query having parameters, resulting in slower than expected query performance.

  • You are referencing a function or command that is unknown to SQL in your query criteria.

    Because SQL Server does not know how to process user-defined Access Basic functions and some built-in Access Basic commands and functions, it cannot evaluate them. As a result, Microsoft Access must locally evaluate them, which can hinder query speed. This applies to all functions not known by SQL, such as the Access Basic IIf() function.

    Note that this behavior applies only when a function unknown to SQL is used in your query criteria. It does not apply when such a function is used in the query's output, except for aggregates such as StDev() that have no SQL equivalent.

RESOLUTION

Make sure to explicitly define all the query parameters before running the query, so that Microsoft Access can send the entire query to the server.

To explicitly define parameters, choose Parameters from the Query menu, and then enter the names and data types of all the parameters used in the query. The "Employee Sales by Country (Parameter)" query in the sample database NWIND.MDB demonstrates this method.

Also make sure to use only functions and commands known to SQL in your query criteria or, if possible, provide additional query restrictions to send to the server. This limits the amount of data returned to Microsoft Access for local user-defined function evaluation. For example, the following query will return all records that are not null:

   Like MyFunction(Forms]![Formname]![Fieldname],*)

Since the sample query above contains MyFunction(), a function unknown to SQL, the query has to be performed locally. Instead, you can get the same results by using the following query, which uses only functions known to SQL:

   Like [Fieldname] or [Fieldname] Is Null

Note that "Forms!Formname!Fieldname" is effectively a query parameter, and should be explicitly declared. It can be declared as:

   Name=Forms!Formname!Fieldname, Type=<yourtype>

STATUS

This behavior no longer occurs in Microsoft Access version 2.0.

REFERENCES

Microsoft Access "User's Guide," pages 182-185


Additional query words: Queries
Keywords : kbusage OdbcOthr
Version : 1.0 1.1
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.