I am creating a simple report using a .NET object from my project as datasource, using SetDatasource() method. However, when I run the report I get "Database logon failed" error. This report is not connecting to a DB at all - have I missed something here? Many thanks, D. ADDED: I guess it will probably help if I include the Controller action. It's a quick and dirty test, not what the final method will look like:
public ActionResult StewardSheets(int showId, int groupId) < ReportClass rptH = new ReportClass(); rptH.FileName = DataHelper.getReportFilePath("Test.rpt",this); NZDSDataContext dataContext = new NZDSDataContext(); var showDetails = (from s in dataContext.Shows where s.ID == showId select new StewardSheetModel < EventDate = s.EventDate.ToLongDateString(), Region = s.Region.Name, ShowTitle = s.Name >).FirstOrDefault(); List details = new List(); details.Add(showDetails); rptH.SetDataSource(details); rptH.Refresh(); Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); return File(stream, "application/pdf"); >
FIXED: D'oh! I used ReportClass instead of ReportDocument. Changed that line, and also use Refresh() since Load() is not a valid method. Now it works just fine!
4,639 3 3 gold badges 34 34 silver badges 42 42 bronze badges asked Nov 30, 2010 at 0:38 2,508 9 9 gold badges 39 39 silver badges 67 67 bronze badges What are the data source settings? Commented Nov 30, 2010 at 0:43Here's a screenshot of the data source - I hope this is what you're asking? img262.imageshack.us/img262/3615/crystalreport.png
Commented Nov 30, 2010 at 5:46If you are using ADO.NET DataSets as your datasource, it is possible for the DataSet definition to get out of sync with the definition in the report. Selecting the Database->Verify Database option from the report designer's context menu will often fix this problem.
Also, you will get this error if your report has linked tables and you fail to set the datasource for one of the tables. The fix is either to remove the table from the report, or set it's datasource correctly.
For example, if your report has a Customers table and an Orders table linked together on some key you will need to set the datasource for both tables. If you forget and set only one, you will get a "Database logon failure" error which is fairly misleading.
// Create a new customer orders report. CustomerOrdersReport report = new CustomerOrdersReport(); // Get the report data. DataTable customersTable = getCustomersData(); DataTable ordersTable = getOrdersData(); // Set datasources. report.Database.Tables["Customers"].SetDataSource(customersTable); report.Database.Tables["Orders"].SetDataSource(ordersTable ); // Don't forget this line like I did!!