FIX: When you run a program or a Web browser script that uses the Command object in the ADO programming interface to run a SQL Server stored procedure, you may receive an "EXECUTE permission denied on object..." error message in SQL Server 2000
Microsoft distributes SQL Server 2000 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2000 fix release.
When you run a program or a Web browser script that uses the Command object in the Microsoft ActiveX Data Objects (ADO) programming interface to run a SQL Server stored procedure, you may receive an error message that is similar to the following:
This problem occurs when all the following conditions are true:
The EXECUTE Transact-SQL statement that is used to call the stored procedure is prepared by using the Prepare property of the Command object.
The main stored procedure that is run from the program or from the Web browser script makes a call to a nested stored procedure.
The user account that is used to connect to the SQL Server database has EXECUTE permissions on the main stored procedure, but does not have EXECUTE permissions on the nested stored procedure.
Service pack information
To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
290211 How to obtain the latest SQL Server 2000 service pack
The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
Note Because of file dependencies, the most recent hotfix or feature that contains these files may also contain additional files.
To work around the problem, use one of the following methods.
In your program or in your Web browser script, do not prepare the statement to call the stored procedure. To do this, set the Prepare property of the Command object to FALSE.
In the SQL Server database, grant EXECUTE permissions on the nested stored procedure to the user account that is used by the program or by the Web browser script to connect to the database.
Note Contact your SQL Server database administrator before you grant EXECUTE permissions to the user account.
Insert a dummy SELECT statement in the main stored procedure just before the EXECUTE statement that calls the nested stored procedure, and then re-compile the main stored procedure. The dummy SELECT statement can be similar to the following:
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.This problem was first corrected in Microsoft SQL Server 2000 Service Pack 4.
If the user account has EXECUTE permissions on the main stored procedure, the main stored procedure must call the nested procedure successfully, even if the user account does not have EXECUTE permissions on the nested stored procedure.
Steps to Reproduce the Behavior
Start SQL Query Analyzer.
Log in to your SQL Server database as the System Administrator.
Run the following Transact-SQL script by using SQL Query Analyzer.
Note If testlogin is a valid user name, and mainproc and nestedproc are valid stored procedure names for your SQL Server database, you must replace them with a different user name and different stored procedure names.
use pubsgo-- Create the nestedproc stored procedurecreate procedure nestedprocasbegin declare @i int select 'OK'endgo-- Create the mainproc stored procedurecreate procedure mainproc asbegin declare @i int set @i=1 -- Nested stored procedure call exec nestedprocendgo-- Create login and grant accessexec sp_addlogin 'testlogin'exec sp_grantdbaccess 'testlogin','testlogin'exec sp_defaultdb 'testlogin','pubs'grant execute on mainproc to testlogingo
Create a Microsoft Visual Basic script file that is named Test.vbs by using the following code.
Note Replace SQL Server Name with the name of your instance of SQL Server.