SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


UNABLE TO EXECUTE TO SP USING OPEN ROW SET


UNABLE TO EXECUTE TO SP USING OPEN ROW SET

Author
Message
syamala.popuri
syamala.popuri
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
Points: 89 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
Stejones
Stejones
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 323
edit: blah I can't read, sorry about that...
Muhammad Tariq
Muhammad Tariq
Old Hand
Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)

Group: General Forum Members
Points: 328 Visits: 245
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
syamala.popuri
syamala.popuri
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
Points: 89 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
vermontloghome
vermontloghome
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 47
I had the same problem.
When I commented out all the RAISERROR statements, it worked fine.
Sad
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search