Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report - code to change server name 1

Status
Not open for further replies.

JoeAtWork

Programmer
Jul 31, 2005
2,285
CA
I've written a C# (2.0) Windows application which has a Crystal report that pulls it's data from a stored procedure (with one input parameter) from SQL Server 2005 Express.

Report works on the development computer.

But when deployed to another computer, my code to set the database server name does not work. Instead, it prompts me with a dialog box to enter the connection parameters, but the server name and database names are greyed out (and set to my development machine).

Here is my code:
Code:
        private void ConfigureCrystalReports()
        {
            ConnectionInfo connInfo = new ConnectionInfo();


            ReportDocument oRpt = new ReportDocument();
            oRpt.Load(Application.StartupPath + "\\BOL_Printout.rpt");

            CrystalDecisions.Shared.TableLogOnInfo crLogonInfo;
            crLogonInfo = oRpt.Database.Tables[0].LogOnInfo;
            crLogonInfo.ConnectionInfo.ServerName = GetServerName();
            crLogonInfo.ConnectionInfo.UserID = GetUserName();
            crLogonInfo.ConnectionInfo.Password = GetPassword();
            crLogonInfo.ConnectionInfo.DatabaseName = GetDatabaseName();

            oRpt.Database.Tables[0].ApplyLogOnInfo(crLogonInfo);

            CrystalVwr.ReportSource = oRpt;


            ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
            parameterDiscreteValue.Value = BOL_ID.ToString();
            ParameterValues currentParameterValues = new ParameterValues();
            currentParameterValues.Add(parameterDiscreteValue);
            CrystalVwr.ParameterFieldInfo[0].CurrentValues = currentParameterValues;
        }

        private void frmPrintout_Load(object sender, EventArgs e)
        {

            ConfigureCrystalReports();
        }

I've confirmed that my GetServerName() function is returning the correct server name from message boxes I've placed in the code.

 
2 options:
1. push the data to the report using a datatable instead of pulling the data from a stored proc.
2. get a listing of the databases/tables. loop through each and assign the proper security settings.

I have seen samples online about option 2. I have never used this though. I use option 1 instead.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I think I like your option number 1, although I have no code samples how to do that. I will do some more Googling (but if you happen to have a link....).


 
1st you'll need a strongly typed dataset which you use to design the report.

so for example you have 1 table with 2 columns
Code:
MyDataSet
{
   MyTable
   {
      Column1 (int)
      Column2 (string)
   }
}
to populate the report
Code:
DataSet ds = new MyDataSet();
new ReportDocument().SetDataSource(ds);
the ds variable must have the same table/column definations as the strongly typed dataset. the easiest remedy for that is to use the strongly typed datset to define the object.

I could have done this as well
Code:
DataSet ds = new DataSet();
ds.Columns.Add("Column1", typeof(int));
ds.Columns.Add("Column2", typeof(string));
new ReportDocument().SetDataSource(ds);

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top