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

Save SP to table Expand / Collapse
Author
Message
Posted Thursday, March 14, 2013 2:21 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, March 14, 2013 9:22 AM
Points: 32, Visits: 1,213
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
Post #1430812
Posted Thursday, March 14, 2013 6:24 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
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.

 
Post #1430914
Posted Thursday, March 14, 2013 8:52 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, March 14, 2013 9:22 AM
Points: 32, Visits: 1,213
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
Post #1431031
Posted Thursday, March 14, 2013 9:13 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 7:45 PM
Points: 23,081, Visits: 31,620
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.





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)
Post #1431048
Posted Thursday, March 14, 2013 9:33 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, March 14, 2013 9:22 AM
Points: 32, Visits: 1,213
Lynn, you saved my day

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

Thank you very much for your help!


Jörg A. Stryk
MVP - MS Dynamics NAV
Post #1431063
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse