Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Execute as 'sa'

Author  Topic 

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2008-04-15 : 12:26:05
I have two instances running on a machine...
The following code will run on the named instance but not on the default instance.

On the default instance I get the following error:
Cannot execute as the user 'SA', because it does not exist or you do not have permission.

However if I specify another account it does work.


use dbReport
go
DROP procedure dbo.clarktest
GO
create procedure dbo.clarktest
WITH EXECUTE AS 'SA' -- 'Domain\SqlCmdShellDev'
as
EXEC xp_cmdshell 'dir'
go
grant exec on clarktest to [spexec]
exec clarktest
use master
go

Any assistance is appreciated as the developers code needs to be coded generically i.e. "sa" this is to prevent code manipulation during migrations...
Thank you

You can do anything at www.zombo.com

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-15 : 13:15:52
do you have SA login created?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2008-04-15 : 13:21:55
Yes sa is created adn sql & nt auth is enabled


You can do anything at www.zombo.com
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-15 : 13:22:47
what permissions does the user you log in with have?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2008-04-15 : 13:28:00
I am currently testing with my account... NT, sysadmin

You can do anything at www.zombo.com
Go to Top of Page
   

- Advertisement -