After reading an article
http://www.sommarskog.se/share_data.html by Erland Sommarskog, SQL Server MVP, Ifound the answer -- OpenQuery issues a SET IMPLICIT_TRANSACTIONS ON statement and so upon disconnect it rollsback any actions. I had suspected something like this!
So if you Commit the Transaction and then open a new one do the following you can get the OpenQuery to work
--Uses local server just for example -- can use on other linked servers
DECLARE @LSExists int
EXEC @LSExists = sp_helpserver @server = 'LOCALSERVER'
IF @LSExists = 1
BEGIN
EXEC sp_addlinkedserver @server = 'LOCALSERVER', @srvproduct = '',
@provider = 'SQLOLEDB', @datasrc = @@servername
END
Use Pubs
-- setup test scenario
DENY SELECT ON authors to PUBLIC
--Verify that
EXEC sp_helprotect @name = 'authors'
, @username = 'PUBLIC'
SELECT * FROM OPENQUERY(LOCALSERVER,'SELECT ''x'' as t Use pubs GRANT SELECT ON dbo.authors TO PUBLIC commit tran')
EXEC sp_helprotect @name = 'authors'
, @username = 'PUBLIC'
David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com