missing schema name from internal queries results in "You have no privilege to this routine"

itsho's profile image itsho posted 10 years ago in General Permalink
Hi.

When I'm selecting a Stored procedure, the next command is running:
EXEC sp_helptext '<STORED_PRECEDURE_NAME>';

and the immediate result i get is
SQL Error (15009): The object 'STORED_PRECEDURE_NAME' does not exist in database 'DATABASE_NAME' or is invalid for this operation. */


the reason for this is that the SCHEMA_NAME is missing from the query. and actually it should run this command:
EXEC sp_helptext '<SCHEMA_NAME>.<STORED_PRECEDURE_NAME>';



I'm using HeidiSQL 9.1.0.4867 and MSSQL 10.0.6000

thanks smile
itsho's profile image itsho posted 10 years ago Permalink
this is somehow related to this issue:
http://www.heidisql.com/forum.php?t=12495

I think that it is possible to fix the issue with a minor change in source file (HeidiSQL 9.1 (11 Nov 2014))
dbconnection.pas



instead of this line (twice - 2701 & 2746)
Rows := GetCol('EXEC sp_helptext '+EscapeString(Name));


use this line
Rows := GetCol('EXEC sp_helptext '+EscapeString(Schema)+'.'+EscapeString(Name));


for some reason I couldn't compile the project on my machine (even without changes) so I couldn't test my assumption.
ansgar's profile image ansgar posted 10 years ago Permalink
After modifying these both lines I can't access my procedures any longer:
EXEC sp_helptext 'dbo'.'sp_MScleanupmergepublisher';
/* SQL Error (102): wrong syntax near '.'. */

That results in a non-functional procedure editor. MSSQL Server 11.0
itsho's profile image itsho posted 10 years ago Permalink
Rows := GetCol('EXEC sp_helptext '+EscapeString(Schema+'.'+Name));
Code modification/commit 36bf8ad from ansgar.becker, 10 years ago, revision 9.1.0.4892
MSSQL: More compatibility when getting procedure body. See http://www.heidisql.com/forum.php?t=17314
ansgar's profile image ansgar posted 10 years ago Permalink
Oh, yes that works. Done in r4892
itsho's profile image itsho posted 10 years ago Permalink
thanks :-)

Please login to leave a reply, or register at first.