I have simplified this statement to use dynamic sql. I know in this case I do not have to use dynamic sql, but I need to find a way to implement security with dynamic sql within a stored procedure. Here it is:
create table test
(idno integer identity(1,1),
tdata varchar(25))
CREATE proc usp_insert_test
(
@data varchar(25))
AS
begin
declare @ret integer
declare @sqlstr varchar(255)
select @sqlstr = 'insert test values(''' + @data + ''')'
execute (@sqlstr)
return
end
GO
I do not have permissions to the test table. I have granted "execute" permission to the stored procedure, but when I call the stored procedure I get:
Server: Msg 229, Level 14, State 5, Line 1
INSERT permission denied on object 'test', database 'TESTDB', owner 'dbo'.
Any thoughts on how I can grant execute premission to allow the inserts only through the stored procedure?
Thank you.
create table test
(idno integer identity(1,1),
tdata varchar(25))
CREATE proc usp_insert_test
(
@data varchar(25))
AS
begin
declare @ret integer
declare @sqlstr varchar(255)
select @sqlstr = 'insert test values(''' + @data + ''')'
execute (@sqlstr)
return
end
GO
I do not have permissions to the test table. I have granted "execute" permission to the stored procedure, but when I call the stored procedure I get:
Server: Msg 229, Level 14, State 5, Line 1
INSERT permission denied on object 'test', database 'TESTDB', owner 'dbo'.
Any thoughts on how I can grant execute premission to allow the inserts only through the stored procedure?
Thank you.