Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Save SP to table


Save SP to table

Author
Message
stryk
stryk
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 1223
Hi there!

Hmmm ... actually I read a lot of articles about how to accomplish that, and indeed I could make this work in another case ... but this time I always get an error like "you cannot have nested INSERT EXEC commands" or something (the original message is in German).

This is what I try:

CREATE TABLE #mirroring_stats
(
[database_name] SYSNAME
,[role] INT
,[mirroring_state] INT
,[witness_status] INT
,[log_generation_rate] INT
,[unsent_log] INT
,[send_rate] INT
,[unrestored_log] INT
,[recovery_rate] INT
,[transaction_delay] INT
,[transactions_per_sec] INT
,[average_delay] INT
,[time_recorded] DATETIME
,[time_behind] DATETIME
,[local_time] DATETIME
)


INSERT INTO #mirroring_stats
(
[database_name]
,[role]
,[mirroring_state]
,[witness_status]
,[log_generation_rate]
,[unsent_log]
,[send_rate]
,[unrestored_log]
,[recovery_rate]
,[transaction_delay]
,[transactions_per_sec]
,[average_delay]
,[time_recorded]
,[time_behind]
,[local_time]
)
EXEC msdb..sp_dbmmonitorresults
@database_name = 'NAV_Mirroring'
,@mode = 0
,@update_table = 1

SELECT * FROM #mirroring_stats

DROP TABLE #mirroring_stats



So actually I want to save the output of sp_dbmmonitorresults into a temporary table ...

What am I doing wrong???

Any help appreciated!

Cheers,
Jörg

Jörg A. Stryk
MVP - MS Dynamics NAV
Steven Willis
Steven Willis
SSC-Addicted
SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)SSC-Addicted (477 reputation)

Group: General Forum Members
Points: 477 Visits: 1721
Does this return anything?



IF OBJECT_ID ( N'msdb.dbo.dbm_monitor_data', N'U' ) IS NULL
SELECT 'No data'
ELSE
SELECT * FROM msdb.dbo.dbm_monitor_data




or this?



SELECT
*
FROM
msdb.dbo.dbm_monitor_data
WHERE
database_id = OBJECT_ID(''NAV_Mirroring'')




Maybe there's no data to read? On my local machine these commands return null.

If I run the procedure



EXEC msdb..sp_dbmmonitorresults
@database_name = 'LocalTestDB'
,@mode = 0
,@update_table = 1




I get this error:

Msg 32039, Level 16, State 1, Procedure sp_dbmmonitorupdate, Line 99
The database 'LocalTestDB' is not being mirrored. No update of the base table was done.

I also noticed that the mirroring stats values as declared inside msdb..sp_dbmmonitorresults are TINYINT rather than INT on a few of the variables. I don't see how that would make any difference, but it's just an observation.

Sorry I can't offer any more help than this.

 
stryk
stryk
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 1223
Thanks for your reply. Yes, I have create a test scenario making sure there is some data; your queries give indeed some result.
Also when I just execute this ...

EXEC msdb..sp_dbmmonitorresults 
@database_name = 'NAV_Mirroring'
,@mode = 0
,@update_table = 1



... I get/see the desired data. But now I want to save this into a #table; but when I try this, I get this "nesting INSERT EXECUTE" error ...

But maybe there would be a different way? Actually all this is to finally read the "time_behind"!
Is there an easier way to retrieve this info?

Jörg A. Stryk
MVP - MS Dynamics NAV
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24177 Visits: 37948
The system procedure msdb.sys.sp_dbmmonitorresults calls msdb.sys.sp_dbmmonitorupdate. Within this procedure there is an insert into @results exec (@command). As such, you use insert into #mirroring_stats exec msdb..sp_dbmmonitorresults @database_name = 'NAV_Mirroring', @mode = 0, @update_table = 1.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
stryk
stryk
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 1223
Lynn, you saved my day :-P

OK, now I run the "update" separately ...

EXEC msdb.sys.sp_dbmmonitorupdate @database_name = 'Navision-SQL'



... and then I execute the "results" without the update:

EXEC msdb..sp_dbmmonitorresults 
@database_name = 'Navision-SQL'
,@mode = 0
,@update_table = 0



Now everything could be inserted into that table for further processing w00t

Thank you very much for your help!

Jörg A. Stryk
MVP - MS Dynamics NAV
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