October 22, 2010 at 7:09 am
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
October 22, 2010 at 7:40 am
edit: blah I can't read, sorry about that...
October 22, 2010 at 7:49 am
Try below updated query;
I Just added a set option (FMTONLY) before procedure execution
[Code="sql"]
select A.*
FROM
OPENROWSET ('SQLNCLI10','server=ABCD;trusted_connection=yes',
'SET FMTONLY OFF EXEC [SP_SQL_Database_Details_STASQL1_ToReport]')as A
[/code]
Tariq
master your setup, master yourself.
http://mssqlsolutions.blogspot.com
October 25, 2010 at 12:47 am
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
October 23, 2013 at 11:45 am
I had the same problem.
When I commented out all the RAISERROR statements, it worked fine.
🙁
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply