Link to home
Start Free TrialLog in
Avatar of pagefigaro
pagefigaroFlag for United States of America

asked on

integrated crystal report prompting for datasource

I have a program that was created in Visual Studio 2005 and then upgraded to Visual Studio 2008. It is written in C#. The database is sql. MSDE instance is running on local PC. On the PC that the database is running on, the program will not run any of the integrated Crystal Reports. It wants me to type in the username and password for the datasource. The datasource that it is looking for is not correct. They worked fine when the reports were using Crystal Reports 10 and not the integrated Crystal builder that comes with VS 2008. I do know that the reports work though because I can display them on the PC that is not running the db. The program uses an ".ini" file to send the datasource and password parameters. Both PC's are XP Pro. Both have the same Crystal Reports Runtime component. Both have the same versions of .NET Framework installed. Any insight/help would be very appreciated!
Avatar of Mike McCracken
Mike McCracken

What code is used to pass the datasource?

What is in the ini file?

mlmcc
I think you line about " The datasource that it is looking for is not correct" provides the key.
 Without knowing any more about your setup, it seems you either need to change the reports to use a datasource that really does exist on the pc with the database OR setup a datasource on the pc with the database that matches the expectations of the report.
If you can open the report on the pc with the db, you should be able to update the report to use the correct datasource.
 
Avatar of pagefigaro

ASKER

This is the ini file:
[LOG]
LogON=YES
[DATA]
DATASOURCE=JENRUPP
MISDB=finney
[FACTOR]
MARGINFACTOR=.6
LOWESTFACTOR=.9
CONSIGNMENTFACTOR=.33
[TEMP]
TEMP=3526
[OTHER]
PREVIEW=OFF
X=10
Y=10
LINEWIDTH=110
LABELPRINTER=LABEL
RECEIPTPRINTER=RECEIPT
PARASTART=590
TOPRINTER=YES
TIMEOUT=1000
TIMERON=YES
[LABELFONT]
FONT=FRANCINEHMKBOLD
SIZE=11

case "GROSSPROFIT":
					try
					{
				
						GrossProfit1 custReport = new GrossProfit1();
						custReport.SetDatabaseLogon("sa","sa");
 
						
				
 
						ParameterFields myParams = new ParameterFields();  
						ParameterField myParam = new ParameterField();  
						ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();
						myParam.ParameterFieldName = "BeginTime";
						ShipDate frmShipDate = new ShipDate();
						frmShipDate.Text = "Enter Start Date";
						DialogResult result = frmShipDate.ShowDialog();
						
 
						DateTime queryDateBegin;
						queryDateBegin = Convert.ToDateTime( frmShipDate.Shipdate);
						frmShipDate.Dispose();
						myDiscreteValue.Value = queryDateBegin;
 
						myParam.CurrentValues.Add(myDiscreteValue);
 
						myParams.Add(myParam);
 
						ParameterField myParam1 = new ParameterField();  
						ParameterDiscreteValue myDiscreteValue1 = new ParameterDiscreteValue();
						myParam1.ParameterFieldName = "EndTime";
 
						DateTime queryDateBegin1 = today.AddDays(1);
 
						frmShipDate = new ShipDate();
						frmShipDate.Text = "Enter End Date";
						result = frmShipDate.ShowDialog();
						string strTest = frmShipDate.Shipdate;
 
						
						queryDateBegin1 = Convert.ToDateTime( frmShipDate.Shipdate + " 23:59:59");
 
						frmShipDate.Dispose();
 
						myDiscreteValue1.Value = queryDateBegin1;
 
						myParam1.CurrentValues.Add(myDiscreteValue1);
 
						myParams.Add(myParam1);
 
 
						crystalReportViewer1.ParameterFieldInfo = myParams;
 
 
						crystalReportViewer1.ReportSource = custReport;
						custReport.Refresh();
					
					}
					catch(Exception test)
					{
						MessageBox.Show(test.Message);
					}
					break;
					#endregioncase "GROSSPROFIT":
					try
					{
				
						GrossProfit1 custReport = new GrossProfit1();
						custReport.SetDatabaseLogon("sa","sa");
 
						
				
 
						ParameterFields myParams = new ParameterFields();  
						ParameterField myParam = new ParameterField();  
						ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();
						myParam.ParameterFieldName = "BeginTime";
						ShipDate frmShipDate = new ShipDate();
						frmShipDate.Text = "Enter Start Date";
						DialogResult result = frmShipDate.ShowDialog();
						
 
						DateTime queryDateBegin;
						queryDateBegin = Convert.ToDateTime( frmShipDate.Shipdate);
						frmShipDate.Dispose();
						myDiscreteValue.Value = queryDateBegin;
 
						myParam.CurrentValues.Add(myDiscreteValue);
 
						myParams.Add(myParam);
 
						ParameterField myParam1 = new ParameterField();  
						ParameterDiscreteValue myDiscreteValue1 = new ParameterDiscreteValue();
						myParam1.ParameterFieldName = "EndTime";
 
						DateTime queryDateBegin1 = today.AddDays(1);
 
						frmShipDate = new ShipDate();
						frmShipDate.Text = "Enter End Date";
						result = frmShipDate.ShowDialog();
						string strTest = frmShipDate.Shipdate;
 
						
						queryDateBegin1 = Convert.ToDateTime( frmShipDate.Shipdate + " 23:59:59");
 
						frmShipDate.Dispose();
 
						myDiscreteValue1.Value = queryDateBegin1;
 
						myParam1.CurrentValues.Add(myDiscreteValue1);
 
						myParams.Add(myParam1);
 
 
						crystalReportViewer1.ParameterFieldInfo = myParams;
 
 
						crystalReportViewer1.ReportSource = custReport;
						custReport.Refresh();
					
					}
					catch(Exception test)
					{
						MessageBox.Show(test.Message);
					}
					break;
					#endregion

Open in new window

Take a look here, page.  I was digging through my code snippets, but this was faster
http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_23477937.html
The key pieces shown below

  ConnectionInfo connectionInfo = new ConnectionInfo(); //our connection details
 
            try
            {
 
                connectionInfo.DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DataBaseName"].ToString(); // cms database change to production
                string username = Session["strUserCMSName"].ToString();//cms username 
                connectionInfo.UserID = username;
                connectionInfo.Type = ConnectionInfoType.CRQE; //SQL;//sql server 
 
                string password = Session["strUserPassword"].ToString();//cms password
                connectionInfo.Password = password;
                connectionInfo.ServerName = System.Configuration.ConfigurationManager.AppSettings["DataBaseServer"].ToString(); //changing to our production database server
            }
            catch (Exception ex) 
            {
                lblerror.Text = ex.ToString();
                return; 
            } 
 
 
 
  private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
        {
            //loop over each table in the reports and set the logon/connection info
            Tables tables = reportDocument.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
            {
                TableLogOnInfo tableLogonInfo = table.LogOnInfo;
                tableLogonInfo.ConnectionInfo = connectionInfo;
                table.ApplyLogOnInfo(tableLogonInfo);
                table.Location = "dbo." + table.Location;//this line is crutial for some sql configs - you may or not need it
            }
        }

Open in new window

Topdog: When I run the report from the program, it brings up a prompt that asks for credentials. It shows the datasource and database name but they are greyed out along with the username. On the other PC, this prompt does not come up, it just goes directly to the report. If the datasource and database name were not greyed out, I could change them and it would work. Problem is, it probably would happen the next time I ran the report. I cannot literally open the report on the PC with the database because it doesn't really exist. The report is compiled into the exe file. Hope that helps.
You have to change the code to set the location of the database or make sure it is in the same place on all PCs.

The report saves the database location in the report and tries to use it.  THe report doesn't use the INI file to get the database though the program may.

mlmcc
mlmcc: the report(s) work fine on the other PC that doesn't house the db. the ini files are the same on each PC.
topdog: where would i put that code? when i call the report?
What machine were the reports developed on?

mlmcc
they are developed on my work machine. They were orginally created using Crystal Reports 10. i had imported them into visual studio 2008. Since then, I have recreated every report using the integrated Crystal in VS 2008.
Exactly
topdog770: what do you mean by "exactly"
ASKER CERTIFIED SOLUTION
Avatar of pagefigaro
pagefigaro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial