How to use SQL Server Reporting Services URL Access to save rendered PDF-Reports as varbinary into Table

huangapple go评论85阅读模式
英文:

How to use SQL Server Reporting Services URL Access to save rendered PDF-Reports as varbinary into Table

问题

I'm trying to store rendered pdf-reports from the Report Server back into a table of the origin database as a varbinary. My current approach would be to use URL-Access inside of an external python script to get the rendered reports and then save them into the corresponding table. The following URL works as expected in the browser: http://localhost/reportserver?/ReportingServicesTest/Report_Test&rs:Format=PDF However when I tried to access that URL inside of the external python script I received a 401 error. So I then tried to use the requests_ntlm library to pass the username and password, but somehow it still doesn't work.

import requests
from requests_ntlm import HttpNtlmAuth

url = 'http://localhost/reportserver?/ReportingServicesTest/Report_Test&rs:Format=PDF'
session = requests.Session()
session.auth = HttpNtlmAuth('Domain\Username','password')
response = session.get(url,stream=True)
open('C:/Path/Report_Test.pdf', 'wb').write(response.content)

Is my approach in principle correct or are there better ways to accomplish the same thing? I'm fairly new to SQL Server Reporting Services, so I'm open to your suggestions and appreciate your help in advance.

英文:

I'm trying to store rendered pdf-reports from the Report Server back into a table of the origin database as a varbinary. My current approach would be to use URL-Access inside of an external python script to get the rendered reports and then save them into the corresponding table. The following URL works as expected in the browser:
http://localhost/reportserver?/ReportingServicesTest/Report_Test&rs:Format=PDF

However when I tried to access that URL inside of the external python script I received a 401 error.
So I then tried to use the requests_ntlm library to pass the username and password, but somehow it still doesn't work.

import requests
from requests_ntlm import HttpNtlmAuth

url = 'http://localhost/reportserver?/ReportingServicesTest/Report_Test&rs:Format=PDF'
session = requests.Session()
session.auth = HttpNtlmAuth('Domain\\Username','password')
response = session.get(url,stream=True)
open('C:/Path/Report_Test.pdf', 'wb').write(response.content)

Is my approach in principle correct or are there better ways to accomplish the same thing?
I'm fairly new to SQL Server Reporting Services, so I'm open to your suggestions and appreciate your help in advance.

答案1

得分: 0

如果需要为安全保管或审计目的保留历史数据,我强烈建议将数据存储在数据库中。使用一个暂存环境来向报表数据添加时间戳,这样快照就会更有意义。这样,您以后可以在 SSRS 门户上使用特定历史版本(参数化)进行筛选,而无需构建专用的 PDF 查看器。这也将节省一些数据库存储空间。作为替代方案,您可以在 SSRS 中创建一个订阅,将 PDF 发送到文件共享。然后配置一个监听器来获取您的元信息,并将该引用存储在数据库表中。不用说,我不太喜欢将文件存储在数据库中,因为文件存储通常比数据库存储便宜。

要解决身份验证问题,您可能需要检查 Web 服务器上的 rsreportserver.config 文件,因为您的当前代码表明您的本地主机不知道任何域。无论如何,您可以尝试更改 <Authentication/> 部分,使其看起来像这样:

<Authentication>
  <AuthenticationTypes>
    <RSWindowsBasic>
      <LogonMethod>3</LogonMethod>
      <Realm></Realm>
      <DefaultDomain>putyourfullyqualifieddomainnamehere</DefaultDomain>
    </RSWindowsBasic>
  </AuthenticationTypes>
  <RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel>
  <RSWindowsExtendedProtectionScenario>Proxy</RSWindowsExtendedProtectionScenario>
  <EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>

如果您的 Web 服务器在代理或防火墙后面,这也会起作用。

重要提示:DefaultDomain 的内容应该是一个完全合格的域名(FQDN),例如 contoso.microsoft.com 或 myprimarydomain.lan。

英文:

IMHO if you need to historic data for safekeeping or auditing purposes I'd strongly recommend to keep the data in the database. Use a staging environment to add a timestamp to the report data so the snapshots make more sense. In this way you can use the SSRS portal later on to filter on a particular historic version (parameterized) and you don't have to build a bespoke PDF viewer. It would also save some database storage. As an alternative, you could create a subscription in SSRS, have the PDF send to a file share. Then configure a listener to that directory to get your meta information and store that reference in a database table. Needless to say I'm not a big fan of storing files in the database as file storage is cheaper than database storage most of the time.

To solve your authentication issue you might want to check up on your rsreportserver.config file on your web server as your current code suggests that your local host is unknowing of any domain. In any case you can try changing your &lt;Authentication/&gt; section so that it looks like this:

  &lt;Authentication&gt;
    &lt;AuthenticationTypes&gt;
      &lt;RSWindowsBasic&gt;
        &lt;LogonMethod&gt;3&lt;/LogonMethod&gt;
        &lt;Realm&gt;&lt;/Realm&gt;
        &lt;DefaultDomain&gt;putyourfullyqualifieddomainnamehere&lt;/DefaultDomain&gt;
      &lt;/RSWindowsBasic&gt;
    &lt;/AuthenticationTypes&gt;
    &lt;RSWindowsExtendedProtectionLevel&gt;Off&lt;/RSWindowsExtendedProtectionLevel&gt;
    &lt;RSWindowsExtendedProtectionScenario&gt;Proxy&lt;/RSWindowsExtendedProtectionScenario&gt;
    &lt;EnableAuthPersistence&gt;true&lt;/EnableAuthPersistence&gt;
  &lt;/Authentication&gt;

This will also work if your web server is behind a proxy or firewall.

Important: the content of DefaultDomain should be a FQDN, such as contoso.microsoft.com or myprimarydomain.lan

huangapple
  • 本文由 发表于 2020年1月3日 21:22:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定