Reports for WinForms | ComponentOne
Working with C1Report / Advanced Uses / Data Security / Creating Application-Defined Aliases
In This Topic
    Creating Application-Defined Aliases
    In This Topic

    Another possible scenario is one where you want to allow certain users to see the reports, but you don't want to give them any special authorizations or information about where the data is stored.

    There are two simple ways to achieve this with C1Report. One is by using embedded reports. Load the report definition into your application at design time, using the Load Report dialog box, and the report will be embedded in the application. This way, you don't have to distribute a report definition file and no one will have access to the data source information.

    The second way would be for your application to define a set of connection string aliases. The report definition file would contain the alias, and your application would replace it with the actual connection string before rendering the reports. The alias would be useless in any other applications (such as C1ReportDesigner). Depending on how concerned you are with security, you could also perform checks on the RecordSource property to make sure no one is trying to get unauthorized access to certain tables or fields in the database.

    The following code shows how you might implement a simple alias scheme:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub RenderReport(strReportName As String)
    
      ' load report requested by the user        
      c1r.Load("c:\Reports\MyReports.xml", strReportName)
    
      ' replace connection string alias        
      Dim strConn$        
      Select Case c1r.DataSource.ConnectionString
        Case "CUSTOMERS"        
        Case "EMPLOYEES"        
           strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _         
                    "Data Source=C:\SecureData\People.mdb;" & _        
                    "Jet OLEDB:Database Password=slekrsldksd;"        
        Case "$$SALES"        
          strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _        
                    "Data Source=C:\SecureData\Numbers.mdb;" & _        
                    "Jet OLEDB:Database Password=slkkdmssids;"         
      End Select
    
      ' set connection string, render report         
      c1r.DataSource.ConnectionString = strConn        
      ppv1.Document = c1r      
      
    End Sub
    

    To write code in C#

    C#
    $$copyCode$$
    private void RenderReport(string  strReportName) {
    
      // load report requested by the user        
      c1r.Load("c:\Reports\MyReports.xml", strReportName);       
         
      // replace connection string alias        
      string strConn$;        
      switch (i) { c1r.DataSource.ConnectionString;
      
        case "$$CUSTOMERS";        
        case "EMPLOYEES";        
          strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + _         
                    "Data Source=CSALES";
          strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +         
                   "Data Source=C:\SecureData\Numbers.mdb;" +        
                    "Jet OLEDB:Database Password=slkkdmssids;";        
      }
    
      // set connection string, render report         
      c1r.DataSource.ConnectionString = strConn;        
      ppv1.Document = c1r;        
    }