Solved

SQl server 2005, reporting services, change extentions field in subscriptions table

Posted on 2007-04-05
12
304 Views
Last Modified: 2008-01-09
In ReportServer database where are my parameters held in the subscriptions table.  (ie. the parameters i use to call my report).

And how could I update the ReplyTo part of the Extensions field based on the value in one of my parameters.

The reason I want to do this is because I need to change the reply to email address for all reports that are being run for a certain location, and i don't feel like editing every record, since I have a lot.
0
Comment
Question by:Fraser_Admin
  • 6
  • 6
12 Comments
 
LVL 13

Expert Comment

by:Megan Brooks
Comment Utility
You might be able to do this using a data driven subscription, especially if you can generate the correct list of email addresses for each copy of the report using an SQL query. The output of the query can both supply the reply-to list and supply the same value to a report parameter, if necessary, so that both values match.

I wouldn't recommend querying the ReportServer DB directly if there is a more straightforward way to accomplish the same thing.

I am answering this in a bit of a rush. I will check back later to see if I understood, and if you still need the other information.
0
 

Author Comment

by:Fraser_Admin
Comment Utility
I don't have the ability to do data driven subscriptions since I don't have enterprise edition.

0
 
LVL 13

Expert Comment

by:Megan Brooks
Comment Utility
That does make it harder to do. The parameters are stored in the Parameters column, in an XML fragment similar to that used for ExtensionSettings (used in the solution for your other question 22492290). A given parameter can be extracted using an XPATH query, as in
SELECT     CONVERT(xml, ExtensionSettings ).value(
        '(/ParameterValues/ParameterValue[Name="ReplyTo"]/Value)[1]', 'varchar(255)'
    ) AS ReplyTo,
    CONVERT(xml, Parameters ).value(
        '(/ParameterValues/ParameterValue[Name="ShowProgress"]/Value)[1]', 'varchar(255)')
    AS ShowProgress
FROM         Subscriptions
WHERE     (NOT (CONVERT(xml, ExtensionSettings ).value('(/ParameterValues/ParameterValue[Name="ReplyTo"]/Value)[1]', 'varchar(255)') IS NULL))
This query finds values for the "Reply To" field and for the parameter "ShowProgress" in subscriptions for which "Reply To" is specified.

Changing ReplyTo is difficult because ExtensionSettings is defined as the depricated type 'ntext' instead of 'xml', and I don't know of a way to modify such a column directly. The only way I know of to update an ntext field is with WRITETEXT, which only accepts data from a literal or a parameter. Short of connecting from an application, I don't know how it can be changed, so that would be a question for someone more familiar with that datatype.

The XML itself is easy enough to change, though. For example,
declare @ReplyTo xml
SELECT     @ReplyTo = ExtensionSettings
FROM         Subscriptions
WHERE     SubscriptionID = '967AEA59-3F8E-4A32-8A46-E3D5D3D34445'

SELECT @ReplyTo
SET @ReplyTo.modify('replace value of (/ParameterValues/ParameterValue[Name="ReplyTo"]/Value/text())[1] with "somebody@somewhere.com" ')
SELECT @ReplyTo

You can change the WHERE clause in the first query to anything that selects a single row. The problem now is how to get the result back into Subscriptions.ExtensionSettings.

I suppose one other alternative would be to run a script against the web service and make the changes that way. That's not something I can put together easily right now.
0
 

Author Comment

by:Fraser_Admin
Comment Utility
yea, i would like to be able to edit those xml values if possible.  do you have any idea how to do this?
0
 
LVL 13

Expert Comment

by:Megan Brooks
Comment Utility
As long as the ExtensionSettings column doesn't exceed 4000 characters, it should be possible to create WRITETEXT queries as a literals and execute them within a cursor loop to do what you want. The new XML data would be embedded as a literal within the literal. This is starting to look very kludgey, but I think it would work and it would be easier than writing an application or a script. I will see what I can come up with...
0
 

Author Comment

by:Fraser_Admin
Comment Utility
thanks that would be great.  
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 13

Accepted Solution

by:
Megan Brooks earned 500 total points
Comment Utility
Here is T-SQL that modifies ReplyTo in the Subscriptions table:

declare      @id uniqueidentifier,
      @tp binary(16),
      @es xml,
      @esl int,
      @params xml,
      @oldReplyTo nvarchar(4000),
      @paramVal nvarchar(4000),
      @newEs nvarchar(4000)

declare ChangeReplyTo cursor for
SELECT TEXTPTR(ExtensionSettings), ExtensionSettings, datalength(ExtensionSettings), Parameters
    FROM Subscriptions WHERE (DataSettings IS NULL)

open ChangeReplyTo
fetch next from ChangeReplyTo into @tp, @es, @esl, @params

while @@fetch_status = 0
    begin
    set @oldReplyTo = @es.value(
        '(/ParameterValues/ParameterValue[Name="ReplyTo"]/Value)[1]', 'nvarchar(4000)')

    set @paramVal = @params.value(
        '(/ParameterValues/ParameterValue[Name="ShowProgress"]/Value)[1]', 'nvarchar(4000)')

    if @esl < 7800 AND NOT @paramVal IS NULL
        begin
        print @oldReplyTo
        print @paramVal
        set @es.modify('replace value of (/ParameterValues/ParameterValue[Name="ReplyTo"]/Value/text())[1] with "somebody@somewhere.com" ')
        set @newEs = N'WRITETEXT dbo.Subscriptions.ExtensionSettings @tp N''' + CONVERT(nvarchar(4000), @es) + N''''
        exec sp_executesql @newEs, N'@tp binary(16)', @tp
        end

    fetch next from ChangeReplyTo into @tp, @es, @esl, @params
    end

close ChangeReplyTo
deallocate ChangeReplyTo

Whether it is a good idea to do this or not depends on how 'private' the report server is. If it is used only for a specific application, this solution should be OK. If it is used by many different people for many different things, it may not be.

The two main things to be concerned about are selecting the right subscription records and keeping the length of ExtensionSettings under 4000 characters for those subscriptions that must be modified. This example ignores subscriptions if ExtensionSettings is not less than 3900 characters (7800 bytes), to leave a little room for the ReplyTo field to grow and to leave room for the rest of the WRITETEXT. It also skips records that don't have a particular parameter name (ShowProgress). You can modify the SQL to select the parameters you need, and to further restrict which subscriptions are modified.

The length of ExtensionSettings can become a problem if the subscription contains long strings (TO string, Comment string, etc.). The approach shown here is limited to 4000 characters for the argument to sp_executesql. Slightly more could be squeezed out by using EXECUTE instead, but it would be more work to format the TEXTPTR value. The length check could be refined. It might also be possible to do a partial write back to ExtensionSettings, overwriting just the ReplyTo value, but this could be quite a bit of extra work and would be even more kludgey, and I didn't want to attempt it.

There might be a better way to do this -- I HOPE there is -- but this is what came to my mind, and it worked when I tried it. It would not be this messy if Report Server were not using ntext columns, which are deprecated in SQL Server 2005, to store the XML fragments.
0
 

Author Comment

by:Fraser_Admin
Comment Utility
ok i will give it a try and let you know.  thanks
0
 

Author Comment

by:Fraser_Admin
Comment Utility
OK, first thing I noticed that I forgot to mention to you is that i have several reports that have that same parameter.  I would only like to change just one report.  Where do I find the report name in the subscriptions table?
0
 
LVL 13

Assisted Solution

by:Megan Brooks
Megan Brooks earned 500 total points
Comment Utility
To obtain information about the report itself, as opposed to the subscription, join Subscriptions to _ using the Subscriptions.Report_OID and Catalog.ItemID. If you use a query designer, the join should be added automatically. The report name is Catalog.Name.

For example,
SELECT     Catalog.Path, Catalog.Name, Subscriptions.Description
FROM         Subscriptions INNER JOIN
                      Catalog ON Subscriptions.Report_OID = Catalog.ItemID

That's good if you only need to change one report; you are unlikely to encounter problems with things changing unexpectedly, and you will probably be able to ensure that the ExtensionSettings column doesn't grow too large.

I won't repeat the entire example I gave earlier but the SELECT query in the DECLARE CURSOR now becomes something like
SELECT TEXTPTR(S.ExtensionSettings), S.ExtensionSettings,
      datalength(S.ExtensionSettings), S.Parameters
FROM Subscriptions S INNER JOIN Catalog C ON
      S.Report_OID = C.ItemID
WHERE (S.DataSettings IS NULL) AND (C.Name LIKE 'NameOrPattern')

You can substitute either a single report name or a pattern for 'NameOrPattern'.

0
 
LVL 13

Expert Comment

by:Megan Brooks
Comment Utility
Oops, "_" should have been "Catalog". Lots of finger trouble today. "To obtain information about the report itself, as opposed to the subscription, join Subscriptions to Catalog using the Subscriptions.Report_OID and Catalog.ItemID. If you use a query designer, the join should be added automatically. The report name is Catalog.Name."
0
 

Author Comment

by:Fraser_Admin
Comment Utility
works perfect.  thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now