runbuf() executes x++ code passed to it. The code must be defined as a function and can return a value. Parameters passed to runbuf() will be forwarded, but default parameters won’t work. To show how it works, I am going to use this function to execute code read from an external file. Not very useful and you probably wouldn’t want to allow it, it’s just to show that it can be done (easily).
static void ExecuteCodeFromFile(Args _args)
{
#File
AsciiIo asciiIo = new AsciiIo(“c:\\temp\\findCustomer.xpp”,#io_read);
XppCompiler xppCompiler = new XppCompiler();
Source source;
str line;
CustTable custTable;
;
if (asciiIo)
{
asciiIo.inFieldDelimiter(#delimiterEnter);
[line] = asciiIo.read();
while (asciiIo.status() == IO_Status::Ok)
{
source += #delimiterEnter;
source += line;
[line] = asciiIo.read();
}
if (!xppCompiler.compile(source))
error (xppCompiler.errorText());
custTable = runbuf(source,’4000′);
print CustTable.Name;
}
else
print “Could not open file”;
pause;
}
The external file c:\temp\findCustomer.xpp:
CustTable findCustomer(CustAccount _accountNum)
{
return CustTable::find(_accountNum);
}
First the file c:\temp\findCustomer.xpp is read into source. Source is then compiled and if that goes okay it is executed. As you can see ‘4000’ is passed as a parameter simply by adding it to the runbuf() call. You can also see runbuf returns the function’s return value.
I had trouble getting code compiled that I had written using notepad. As it turns out, the compiler does not accept the tab character. So if you are going to try this out, watch out for that.
Put the following files into your scripts directory as mentioned in the code. I used C:\DBA\SCRIPTS\SSRSRecycle
echo
"starting pre-cache of SSRS site"
$wc
=
New-Object
system.net.webClient
$cred
= [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc
.Credentials =
$cred
$src
=
$wc
.DownloadString(
"http://localhost/Reports/Pages/Folder.aspx"
)
echo
"finished pre-cache of SSRS site"
***Note ‘ReportServerTempDB’ & ”MSSQL$UAT’ will be different you can find these from the event log or work them out quite easily***
YourLogin
<QueryList><Query Id=”0″ Path=”Application”><Select Path=”Application”>*[System[Provider[@Name='MSSQL$UAT'] and (EventID=5084)]] and *[EventData[Data and (Data='COMPATIBILITY_LEVEL')]] and *[EventData[Data and (Data='ReportServerTempDB')]]</Select></Query></QueryList>
S4U
HighestAvailable
true
true
true
false
false
false
true
false
false
false
P3D
7
***Note ‘ReportServerTempDB’ & ”MSSQL$UAT’ will be different you can find these from the event log or work them out quite easily***
<
pre
class
=
"brush: xml;"
> </
pre
>
Stop-Service
"SQL Server Reporting Services (MSSQLSERVER)"
Start-Service
"SQL Server Reporting Services (MSSQLSERVER)"
$wc
=
New-Object
system.net.webClient
$cred
= [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc
.Credentials =
$cred
$src
=
$wc
.DownloadString(
"http//mysharepointsite.com/Tests/ReportServerTest/Reports/Forms/current.aspx"
)
PS C:\Windows\System32> $cred = [System.Net.CredentialCache]::DefaultNetworkCred
entials
PS C:\Windows\System32> $wc.Credentials = $cred
PS C:\Windows\System32> $src = $wc.DownloadString(“http://localhost/reports_ssrs
jt/Pages/Folder.aspx”)
Exception calling “DownloadString” with “1″ argument(s): “The operation has tim
ed out”
At line:1 char:26
+ $src = $wc.DownloadString( <<<< "http://localhost/reports_ssrsjt/Pages/Folder
.aspx")
Set-ExecutionPolicy RemoteSigned
Get-ExecutionPolicy
3. Create a file ssrswakeup.ps1 with these Pawel’s lines in it
$cred = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.Credentials = $cred
$src = $wc.DownloadString(“http://localhost/reports/Pages/Folder.aspx”)
powershell -command “& ‘c:\ssrs\ssrswakeup.ps1′ ”
Account: add an account with permission to open url in $src
Trigger:
On an event -> Custom -> Edit Event Filter-> XML (@Name is your service name)
<
QueryList
>
<
Query
Id
=
"0"
Path
=
"Application"
>
<
Select
Path
=
"Application"
>*[System[Provider[@Name='SQL Server Reporting Services'] and Task = 0]]</
Select
>
</
Query
>
</
QueryList
>
c:\ssrs\wakeup.cmd
<RecycleTime>1440</RecycleTime>
i used your script, but i get this error, could you help me please with this?
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\Windows\System32\WindowsPowerShell\v1.0> C:\Admin\SSRSrecycle\SSRSrecycle.![;)]()
ps1
WARNING: Waiting for service 'SQL Server Reporting Services (MSSQLSERVER)
(ReportServer)' to finish starting...
WARNING: Waiting for service 'SQL Server Reporting Services (MSSQLSERVER)
(ReportServer)' to finish starting...
Exception calling "DownloadString" with "1" argument(s): "The operation has tim
ed out"
At C:\Admin\SSRSrecycle\SSRSrecycle.ps1:6 char:26
+ $src = $wc.DownloadString <<<< ("http://server/Reports/Pages/Folder.aspx"
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
WebClient
has. Unfortuantelly it is not possbile to set longer timeout for theWebClient
without creating a new class and overide parent methods. But even this error has been thrown the initialization of SSRS started and after some while the the report response should be normal.HttpWebRequest
classGetResponse
instead ofWebClient
. TheHttpWebRequest
class has the possibility to setup the timeout. You can take a look on samples on MSDN –HttpWebRequest.GetResponse Method and HttpWebRequest.Timeout Property.Task Scheduler failed to launch action “powershell.exe -noprofile -executionpolicy RemoteSigned -file c:\dnm\RestartSSRS.ps1″ in instance “{f9449b39-316a-4c3a-b9b7-e1e8cdbdfec7}” of task “\SSRS Recycle”. Additional Data: Error Value: 2147942523.
Any idea?
Thanks in advance!
Task category: Action failed to start
Description: Task Scheduler failed to launch action “powershell.exe -noprofile -executionpolicy RemoteSigned -file c:\dnm\RestartSSRS.ps1″ in instance “{46caf0b2-50df-49ad-90d6-0f4f9fd203ae}” of task “\SSRS Recycle”. Additional Data: Error Value: 2147942523.
Then I get:
Task category: Action start failed
Description: Task Scheduler failed to start instance “{46caf0b2-50df-49ad-90d6-0f4f9fd203ae}” of “\SSRS Recycle” task for user “customerdomain\Administrator” . Additional Data: Error Value: 2147942523.
Thanks,
Rob
For this you can ceck this techned thread Using AD to allow a user to start/stop a service
Thanks for your reply. I found the solution. The task manager will not run powershell on 64bit properly. You need to point directly to the 32 bit version, which is located on C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. (see alsohttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/e298d613-47b8-4492-92d1-0b55cc8497c1)
So in the ‘edit action’ window (of the scheduled task) I entered this in the ‘Program/script’ textbox, and the other parameter you mentioned, in the ‘Add arguments’ textbox. Now it works!
[dbo].[ExecutionLogStorage]
to check execution details of the report processing like Data Retrieval Time, Processing or Rendering times.