Answered by:
c# trying to change datasource folder for crystal report

Question
-
I had working fine in my c# project where my crystal report was displaying as it was based on a source in a fixed file location such as d:\devel\temptodo.accdb. Now I'm trying to get it so the access database gets referred from a dynamic folder location for the temp folder
string tmpfn = System.IO.Path.GetTempPath() + "temptodo.accdb";
While it seems my report is searching for the database located in d:\devel, I need it to find it in wherever the temp folder is being used for client purposes, and so far have gotten my viewer code to appear as follows:
rn = DMReferrals.rpt
fn = %temp%temptodo.accdb (c:\temp\temptodo.accdb on my workstation)public FrmReportBySource(string rn, string fn) { InitializeComponent(); ReportDocument cryRpt = new ReportDocument(); cryRpt.Load(rn); cryRpt.DataSourceConnections[0].SetConnection(fn, "DMtodo", false); cryRpt.DataSourceConnections[0].SetLogon("", ""); crystalReportViewer1.ReportSource = cryRpt; crystalReportViewer1.Refresh(); }
what is actually happening is I see a "Please wait while the document is processing" message in background with a spinning wheel, along with a popup message "Logon Failed. Please try again." as I don't have any username nor password for this access database anyways.
intriguingly if I click ok then refresh the report I get the desired output, so I'm guessing there's something minor here.
Please advise on what I need to properly point to my dynamic access file, thanks.
- Edited by jfalberg Tuesday, October 9, 2012 8:15 PM
- Moved by Cindy Meister MVP Wednesday, October 10, 2012 9:06 AM not using VSTO technology (From:Visual Studio Tools for Office)
Tuesday, October 9, 2012 8:10 PM
Answers
-
Hi jfalberg,
You can refer to environment variables with the System.Environment.GetEnvironmentVariable method.
This thread should be moved to Visual Studio .NET Base Class Library forum, or at least to a forum of the .NET Framework category on MSDN.
Regards,
Zoli
- Proposed as answer by Ed Price - MSFTMicrosoft employee Wednesday, October 10, 2012 8:51 PM
- Marked as answer by Just Karl Wednesday, October 17, 2012 1:50 PM
Wednesday, October 10, 2012 9:38 AM -
Visit http://scn.sap.com/community/crystal-reports-for-visual-studio/content?filterID=content~objecttype~objecttype[thread] for help in expected parameters of Crystal Report. I am sure it supports sources other than hard-coded file location.
Visual C++ MVP- Proposed as answer by Ed Price - MSFTMicrosoft employee Wednesday, October 10, 2012 8:51 PM
- Marked as answer by Just Karl Wednesday, October 17, 2012 1:50 PM
Wednesday, October 10, 2012 7:22 PM
All replies
-
Hi jfalberg,
You can refer to environment variables with the System.Environment.GetEnvironmentVariable method.
This thread should be moved to Visual Studio .NET Base Class Library forum, or at least to a forum of the .NET Framework category on MSDN.
Regards,
Zoli
- Proposed as answer by Ed Price - MSFTMicrosoft employee Wednesday, October 10, 2012 8:51 PM
- Marked as answer by Just Karl Wednesday, October 17, 2012 1:50 PM
Wednesday, October 10, 2012 9:38 AM -
Wherever I can figure how to fix this problem is fine with me. If Crystal Reports had a way to detect environment variables such as where the temp folder is on client workstation instead of a static folder then that would easily solve my problem. At this time I still haven't found a working solution to my problem.
edit: as an update, I changed
cryRpt.DataSourceConnections[0].SetConnection(fn, "DMtodo", false);
tocryRpt.DataSourceConnections[0].SetConnection(fn, "", false);
and it worked for me. I'm not sure why an example let me to this but so long as my report works I'm satisfied.
moderators can close this now.
- Edited by jfalberg Wednesday, October 10, 2012 4:03 PM
Wednesday, October 10, 2012 2:47 PM -
Visit http://scn.sap.com/community/crystal-reports-for-visual-studio/content?filterID=content~objecttype~objecttype[thread] for help in expected parameters of Crystal Report. I am sure it supports sources other than hard-coded file location.
Visual C++ MVP- Proposed as answer by Ed Price - MSFTMicrosoft employee Wednesday, October 10, 2012 8:51 PM
- Marked as answer by Just Karl Wednesday, October 17, 2012 1:50 PM
Wednesday, October 10, 2012 7:22 PM -
Hello again as I'm once again trying to figure out what is wrong here. My code for displaying my report is presently as follows:
public FrmReportBySource(string rn, string fn) { InitializeComponent(); ConnectionInfo ciReportConnection = new ConnectionInfo(); ReportDocument cryRpt = new ReportDocument(); cryRpt.Load(rn); cryRpt.DataSourceConnections.Clear(); cryRpt.DataSourceConnections[0].SetConnection(fn, "", false); cryRpt.DataSourceConnections[0].SetLogon("", ""); crystalReportViewer1.ReportSource = cryRpt; crystalReportViewer1.Refresh(); }
where rn is my report file and fn is my access data source. The problem I'm having is when I go to refresh the report with the updated data source it does not seem to refresh from the pre-saved report unless I manually press F5 on the report output. Am I missing something else here?
edit: by adding cryRpt.Refresh(); it seemed to work at least.- Edited by jfalberg Wednesday, May 8, 2013 3:08 PM
Wednesday, May 8, 2013 3:05 PM