有没有办法将连接字符串硬编码为 RDLC?

发布于 2024-11-29 04:44:05 字数 1796 浏览 1 评论 0原文

我需要制作可以在本地处理报告的报告查看器。 我得到了带有查询的 RDL 文件。有没有办法将连接字符串插入 报告的XML代码以便报告可以直接从数据库获取数据?报告将 显示在 MS reportViewer 中。

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">
  <DataSources>
    <DataSource Name="BIA">
      <DataSourceReference>BIA</DataSourceReference>
      <rd:DataSourceID>98fa74a9-d829-4196-be9d-49697ded5201</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="RelItems">
      <Fields>
        <Field Name="RelItemID">
          <DataField>RelItemID</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="SSISPackageName">
          <DataField>SSISPackageName</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>BIA</DataSourceName>
        <CommandText>select b.ID as RelItemID, SSISPName --+ '  ('+s.Name + ' -&gt; ' + d.Name + ')' 
as SSISPackageName
    from dbo.RelTypes_ProvTypes a
    inner join dbo.RelItems b on a.RelTypeID = b.RelTypeID
    inner join dbo.ObjItems s on b.ObjItemIDSource = s.ID and a.ObjTypeIDSource = s.ObjTypeID
    inner join dbo.ObjItems d on b.ObjItemIDDest = d.ID and a.ObjTypeIDDest = d.ObjTypeID
where SSISPName is not null
order by 2</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
      </Query>
    </DataSet>

... and so on

这是我的 RDL。 欢迎任何其他提示或帮助,只需让它发挥作用:)

I need to make report viewer that will handle reports localy.
I got RDL files with querys. Is there a way to insert conenction string into
report's XML code so the report can get data from database directly? reports will
be display in MS reportViewer.

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">
  <DataSources>
    <DataSource Name="BIA">
      <DataSourceReference>BIA</DataSourceReference>
      <rd:DataSourceID>98fa74a9-d829-4196-be9d-49697ded5201</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="RelItems">
      <Fields>
        <Field Name="RelItemID">
          <DataField>RelItemID</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="SSISPackageName">
          <DataField>SSISPackageName</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>BIA</DataSourceName>
        <CommandText>select b.ID as RelItemID, SSISPName --+ '  ('+s.Name + ' -> ' + d.Name + ')' 
as SSISPackageName
    from dbo.RelTypes_ProvTypes a
    inner join dbo.RelItems b on a.RelTypeID = b.RelTypeID
    inner join dbo.ObjItems s on b.ObjItemIDSource = s.ID and a.ObjTypeIDSource = s.ObjTypeID
    inner join dbo.ObjItems d on b.ObjItemIDDest = d.ID and a.ObjTypeIDDest = d.ObjTypeID
where SSISPName is not null
order by 2</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
      </Query>
    </DataSet>

... and so on

This is RDL I have.
Any other tips or help is welcome, just need to make it work :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好倦 2024-12-06 04:44:05

RDL 文件包含未存储在 ReportViewer 控件使用的 RDLC 文件中的查询信息。如果您想在 ReportViewer 中的 SSRS 之外使用 RDL 文件,则可以在本地模式下运行报表时通过代码设置数据源属性。这样,您可以在构建数据源时将连接字符串设置为您想要的任何内容。

ReportViewer1.Reset()
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = <yourfilepath>
ReportViewer1.LocalReport.DataSources.Add(<yourdatasource>)
ReportViewer1.LocalReport.Refresh()

(显然这个片段是VB)

RDL files contain query information that isn't stored in RDLC files as used the ReportViewer control. If you want to use your RDL file outside of SSRS in the ReportViewer then you can set the datasource property from code when running the report in local mode. That way you set the connection string to whatever you want when you build the datasource.

ReportViewer1.Reset()
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = <yourfilepath>
ReportViewer1.LocalReport.DataSources.Add(<yourdatasource>)
ReportViewer1.LocalReport.Refresh()

(obviously this snippet is VB)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文