views:

161

answers:

3

I'm trying to run a stored procedure from my website that disables a trigger. Here is the code for the trigger:

CREATE PROCEDURE [dbo].[DisableMyTrigger]
AS
BEGIN
    alter table dbo.TableName DISABLE TRIGGER TriggerName
END

I've also set the permissions on the stored procedure with:

Grant Exec on dbo.DisableMyTrigger To DBAccountName

DBAccountName is and has been able to run other stored procedures as well as dynamic SQL statements without issue.

Here is the code from my CFM page:

<cfstoredproc datasource="myDatasource" procedure="DisableMyTrigger" />

And here is the error I'm getting:

[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][SQL Native Client][SQL Server]Cannot find the object "TableName" because it does not exist or you do not have permissions.
A: 

Its because your connected to the wrong db Catalog (assuming SQL Server). Your connected to the database but your connected to the "default" catalog, which is probably "master"

I think you can put something in the beginning of your procedure like :

use DBName;

and that will connect you to the proper catalog.

djangofan
YES! this is exactly what im saying above! good call
Eric
Msg 154, Level 15, State 1, Procedure DisableMyTrigger, Line 9a USE database statement is not allowed in a procedure, function or trigger.
Jason
Did you write use database on top of the creation of the stored procedure?
Eric
The 'Use database' will set the db for the compilation of the proc but won't help if the object can't be found at runtime. Not sure what database this is on but I'd bet the proc would not even compile if the object isn't in the catalog. I could be wrong about that.
DaveE
A: 

You may have to specify the database. I don't think it's a permissions issue, i believe it just can't find it in that database.

Eric
+3  A: 

Does DBAccountName have permissions to TableName? These can be granted or revoked separately from the overall schema (dbo).

I'm not a dba, but is DBAccountName allowed to execute DDL statements? (so it can do things like disable triggers programmatically)

DaveE
DBAccountName does have access to Tablename. However, I'm not sure about the 2nd part. I thought by granting that user exec rights on that procedure then it wouldn't matter what's in the procedure.
Jason
@Jason: With MS SQL 2000, three statements: insert, update and delete gained rights via the owner of the stored proc versus the rights of the connection. To do DDL within a stored procedure, the user calling the SP needed the rights to run the DDL. Even TRUNCATE TABLE could not be run unless the user had rights to truncate the table.
Shannon Severance
@Jason: I've added an answer to another question that talks about rights and stored procedures. The error message for other DDL statements is similar to what you are getting. See:http://stackoverflow.com/questions/1139137/what-are-the-ramifications-of-granting-a-db-user-with-limited-access-execute-perm/1141440#1141440
Shannon Severance