Get info from the ConnectionString at runtime

Hi,

We have a WinForms app and at runtime we provide the connection string from our app, as in page 20 off FastReport.Net Programmer's manual:
report1.Dictionary.Connections[0].ConnectionString = my_connection_string

How can we get specific info of the connection string to be printed on the report - we don't need the full connectionstring, only the server and database in use.

By example, we would like to get the server and database defined in the connection string: We try to create a function inside the report, using something like Report.Dictionary.Connections(0).Item(0).ConnectionString but we get an error "BC30456:'Item' is not a member of 'FastReport.Data.DataConnectionBase'.

TIA,

Carlos

Comments

  • edited 5:21PM
    script
    namespace FastReport
    {
      public class ReportScript
      {
        private void _StartReport(object sender, EventArgs e)
        {
          DataConnectionBase dcb = (Report.GetDataSource("YourDataSourceName") as TableDataSource).Connection;
          MessageBox.Show(dcb.ConnectionString);
        }
      }
    }
    

    dictionary section in frx file
      <Dictionary>
        <MsAccessDataConnection Name="Connection" ConnectionString="rijcmlqoDWEBRlB24atBGpA/h9/NbwdWKfjN0xexwR499WDO0y7IJqtWaFegHY0F1Ho9V3Ftyyqs1cgkq332JhWC6OJH9ee34BnqwzyoTKFmGf4cNw=">
          <TableDataSource Name="YourDataSourceName" DataType="System.Int32" Enabled="true" TableName="YourDataSourceName">
            <Column Name="AccCode" DataType="System.String"/>
            <Column Name="AccName" DataType="System.String"/>
          </TableDataSource>
        </MsAccessDataConnection>
      </Dictionary>
    
  • edited 5:21PM
    Thanks interesting code

    Can this be translate into VB script please as my reports using VB code
    Many thanks
    Farhan

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.