
- #Connect visual studio and sql server through web.config pdf#
- #Connect visual studio and sql server through web.config code#
- #Connect visual studio and sql server through web.config password#
#Connect visual studio and sql server through web.config code#
Return True if the code runs to this stage. If (!ApplyLogon(cr.OpenSubreport(subobj.SubreportName), ci)) If (obj.Kind = ReportObjectKind.SubreportObject) foreach (ReportObject obj in cr.ReportDefinition.ReportObjects) If a subreport is found then apply logon information to // the subreport. Loop through all the report objects and locate subreports. We are applying logon information to the main report at this stage.
#Connect visual studio and sql server through web.config password#
Declare and instantiate a new connection info object.Ĭi.Password = password // password // ci.IntegratedSecurity = false // If the ApplyLogon function fails then return a false for this function. The following code is used to log onto each report using SQL server credentials stored in the Web.Config file:Ĭopy Code // Check whether crytal report can login to the server private bool Logon(ReportDocument cr, string server, string database, string user_id, string password) Return File(stream, " application/pdf", savedFileName) String savedFileName = string.Format(reportDescription + ". Stream stream = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat) String reportDescription = db.CustomerMonthlyPaymentsReport.Where(x => x.ReportId = id).Select(x => x.ReportDescription).First() crReportDocument = prepareReport(crReportDocument) Logon(crReportDocument, ServerName, DataBaseName, UserID, Password) crReportDocument.SetDatabaseLogon(UserID, Password) ReportDocument crReportDocument = new ReportDocument() ĬrReportDocument.Load(Path.Combine(Server.MapPath( " ~/Reports/Admin"), " Monthl圜ustomerPayments.rpt")) ĬrReportDocument.SetDataSource(db.CustomerMonthlyPaymentsReport.Where(x => x.ReportId = id).ToList()) String ServerName = .ToString() // Database server name to which report connected string DataBaseName = .ToString() // Database name to which report connected string UserID = .ToString() // Database user name to which report connected string Password = .ToString() // Database user password to which report connected
#Connect visual studio and sql server through web.config pdf#
I have the following code for the PDF export button in the CustomerMonthlyPaymentReportsController:Ĭopy Code public ActionResult ExportReportPDF( int id) So the idea is that the Customer generates a report for a specified date range, save it and then have the option to export the report to PDF or Excel foemat. On this view I have two buttons, one for "Export to PDF" and the other for "Export to Excel". I have a Controller that collects the data for each data table, save it, and then display the report tables in a Razor view. I hope the above makes sense in terms of the setup of the data models and their corresponding reports. The following sub-reports/models are linked via the "ReportId" primary key to the main report/model.Ģ) Customer Summary - "CustomerSummary.rpt" - "CustomerSummary" data model.ģ) Customer Service Fee Summary - "CustomerServiceFeeSummary.rpt" "CustomerServiceFeeSummary" data model.Ĥ) Customer Account Profile Summary - "CustomerAccountProfileSummary.rpt" - "CustomerAccountProfileSummary" data model.ĥ) Customer Account Summary - "CustomerAccountSummary.rpt" - "CustomerAccountSummary" data model.Ħ) Customer Service Summary - "CustomerServiceSummary.rpt" - "CustomerServiceSummary" data model.ħ) Customer Service Transaction Details - "Customer Service Transaction Details" - "CustomerServiceTransactionDetails" data model.

I am using the Crystal Reports for Visual Studio add-in.ġ) Monthly Customer Payments - connects the "Monthl圜ustomerPayments.rpt" report to the "CustomerMonthlyPaymentsReport" data model. In order to allow the user to save reports, I created the following Report Data Models to store the retrieved data from the rest of the application: In summary it collects financial data from several data tables and then display a "statement-like" report for a particular customer.


The particular report I have created is rather complicated. The web application was created using C#, ASP.NET MVC 5, MS SQL 2014, and I use Entity Framework Code-first for my data models. One of the projects contains all my reports. I have a Visual Studio 2017 solution with multiple projects.
