Thursday, September 19, 2013

How to pass logon information to reportdocument object to export in pdf from crystal report in sqlsever2005/2008 and Sql Aure



 logon information to reportdocument object in sqlsever2005/2008




ReportDocument repDoc = new ReportDocument();
   repDoc.Load(repFilePath);

// This is for  logon information to reportdocument object in sqlsever2005/2008
 repDoc.SetDataSource(getCustomerData(clientid));
  repDoc.SetDatabaseLogon("userid", "Password", "Sever Name", "Database name");
  repDoc.SetParameterValue(0, clientid);

//  logon information to reportdocument object in Sql Azure

repDoc.SetDataSource(getCustomerData(clientid));
  repDoc.DataSourceConnections[0].SetConnection("ServerName", "database Name", "User ID", "Password");
   repDoc.DataSourceConnections[0].SetLogon("User id", "Password");
                 
   repDoc.SetParameterValue(0, clientid);


 // Stop buffering the response
                    Console.Clear();
                 
                    ExportOptions CrExportOptions;

                    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                    CrDiskFileDestinationOptions.DiskFileName =  filePathName + ".pdf";
                    CrExportOptions = repDoc.ExportOptions;
                    {
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions = CrFormatTypeOptions;

                    }
                    repDoc.Export();



        // Business layer class to get the data from database
        private DataSet getCustomerData(string clientid)
        {

            SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["SherpaSQLConnString"].ToString());
            SqlCommand cmd = new SqlCommand("ClientMIPage1", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@cclientid", SqlDbType.VarChar, 36));
            cmd.Parameters[0].Value = clientid;
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(ds);
            return ds;

        }


No comments:

Post a Comment