Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

UNABLE TO EXECUTE TO SP USING OPEN ROW SET Expand / Collapse
Author
Message
Posted Friday, October 22, 2010 7:09 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, February 04, 2011 1:22 AM
Points: 15, Visits: 42
Hi All,
I have Stored Procedure as below. I am unable to execute that SP using open row set query, how i can proceed to insert results from sp in remote server(except using linked sever)

Insert Into dbo.Database_Details_Table
select A.*
FROM
OPENROWSET ('SQLNCLI10','server=ABCD;trusted_connection=yes',
'EXEC [SP_SQL_Database_Details_STASQL1_ToReport]')as A
ERROR :Cannot process the object "EXEC [SP_SQL_Database_Details_STASQL1_ToReport]". The OLE DB provider "SQLNCLI10" for linked server "(null)" indicates that either the object has no columns or the current user does not have permissions on that object.
And sp is as fallows..


USE [master]
GO

/**Date: 10/22/2010 06:06:58 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[SP_SQL_Database_Details_STASQL1_ToReport] @dbname sysname = null

as
if @dbname is not null and @dbname not in (select name from SYSDATABASES)
begin
raiserror('relax!... you''re just one step away from the results. please verify the database name is correct and try again. ', 16, 1)
return (1)
end

set nocount on
IF OBJECT_ID ('[tempdb].[dbo].[##DBDETAILS]') IS NOT NULL
BEGIN

DROP TABLE ##DBDETAILS

END
create table ##DBDETAILS
(
Server_name nvarchar(50),
db_name varchar(30) not null primary key clustered,
total dec (7, 1),
data dec (7, 1),
data_used dec (7, 1),
[data (%)] dec (7, 1),
data_free dec (7, 1),
[data_free (%)] dec (7, 1),
log dec (7, 1),
log_used dec (7, 1),
[log (%)] dec (7, 1),
log_free dec (7, 1),
[log_free (%)] dec (7, 1),
status dec (7, 1)
)

set nocount on
insert ##DBDETAILS ( db_name, log, [log (%)], status ) exec ('dbcc sqlperf(logspace) with no_infomsgs')
print '' print ''
if @dbname is null
declare dbname cursor for select name from SYSDATABASES WHERE DBID NOT IN (7,10,15,16) order by name asc
else if @dbname is not null
begin
delete from ##DBDETAILS where db_name <> @dbname
declare dbname cursor for select name from SYSDATABASES WHERE DBID NOT IN (7,10,15,16) and name = @dbname
end
open dbname
fetch next from dbname into @dbname
while @@fetch_status = 0
begin -- adding .0 at the end of interger to avoid divide by zero error
exec ( ' use ' + '['+ @dbname +']'+ ' declare @total dec(7, 1),
@data dec (7, 1),
@data_used dec (7, 1),
@data_percent dec (7, 1),
@data_free dec (7, 1),
@data_free_percent dec (7, 1),
@log dec (7, 1),
@log_used dec (7, 1),
@log_used_percent dec (7, 1),
@log_free dec (7, 1),
@log_free_percent dec (7, 1)
set @total = (select sum(convert(dec(15),size)) from sysfiles) * 8192.0 / 1048576.0
set @data = (select sum(size) from sysfiles where (status & 64 = 0)) * 8192.0 / 1048576.0
set @data_used = (select sum(convert(dec(15),reserved)) from sysindexes where indid in (0, 1, 255)) * 8192.0 / 1048576.0
set @data_percent = (@data_used * 100.0 / @data)
set @data_free = (@data - @data_used)
set @data_free_percent = (@data_free * 100.0 / @data )
set @log = (select log from ##DBDETAILS where db_name = '''+@dbname+''')
set @log_used_percent = (select [log (%)] from ##DBDETAILS where db_name = '''+@dbname+''')
set @log_used = @log * @log_used_percent / 100.0
set @log_free = @log - @log_used
set @log_free_percent = @log_free * 100.0 / @log
update ##DBDETAILS set total = @total,
data = @data ,
data_used = @data_used,
[data (%)] = @data_percent,
data_free = @data_free,
[data_free (%)] = @data_free_percent,
log_used = @log_used,
log_free = @log_free,
[log_free (%)] = @log_free_percent
where db_name = '''+@dbname+'''' )
fetch next from dbname into @dbname
end
close dbname
deallocate dbname

DROP TABLE ##ABC

/*create table ##ABC(
Server_name NVARCHAR(50),
DB_NAME NVARCHAR(50),
TOTAL NVARCHAR(50),
DATA NVARCHAR(15),
DATA_FREE NVARCHAR(15))*/


declare @Server_name nvarchar(50)
set @Server_name =(select @@servername)

if ((select count(*) from ##DBDETAILS ) <> 1)

select @Server_name as Server_name,DB_NAME,TOTAL,DATA,DATA_FREE into ##ABC from ##DBDETAILS

SELECT * FROM [##ABC]

GO


Post #1009159
Posted Friday, October 22, 2010 7:40 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 18, 2013 10:02 AM
Points: 150, Visits: 317
edit: blah I can't read, sorry about that...
Post #1009192
Posted Friday, October 22, 2010 7:49 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 2:10 AM
Points: 138, Visits: 236
Try below updated query;

I Just added a set option (FMTONLY) before procedure execution


select A.* 
FROM
OPENROWSET ('SQLNCLI10','server=ABCD;trusted_connection=yes',
'SET FMTONLY OFF EXEC [SP_SQL_Database_Details_STASQL1_ToReport]')as A




Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
Post #1009198
Posted Monday, October 25, 2010 12:47 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, February 04, 2011 1:22 AM
Points: 15, Visits: 42
I Already tried with set fmt off,but still same error.
Is there any issue with global temp tables(the sp from sql 200 isntance)
i tried to execute in sql 2008 instane. is there any issue in doing this?

Thanks in advance
Post #1009812
Posted Wednesday, October 23, 2013 11:45 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, November 01, 2013 11:21 AM
Points: 1, Visits: 32
I had the same problem.
When I commented out all the RAISERROR statements, it worked fine.
Post #1507776
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse