none
Problem changing database at runtime with crystal report and SQL Server 2005 RRS feed

  • Question

  •  

    Hi,

    Recently i have migrated a windows Form Application from MSAccess to SQL Server.

    With MS Access, i used Crystal Reports and was able to access the reports from the Application easily, During the Migration Process, i converted all the connection to the Crystal Reports from MS Access to SQL. in my Development Environment, when i am running the application, i am able to use the application well including the reports on SQL Server. where as when i am moving the application to the Client Side, the Application runs fine except for the Crystal reports. whenever i try to invoke the Reports part of the application at the client end, it asks for the logon information.

    I have provided all the required Logon information to all the tables used in the report viz: ServerName. DBName, User ID and the Password. here i am using the SQL authentication and not the integrated authentication.

    While running the Report part, it asks for the logon info and even if i supply the password, it says logon failed.

    Here i would like to add: i am just replacing the EXE File compiled during the debug process from the new environment. the old exe used MSAccess Logon info. and the new EXE is using the SQL Logon info

    Need Help.

    attached is one of the reports i am using. it takes the start date and takes the end date and passes them as parameter to the crystal report. similar thing was done for MSAccess. the only difference between the code below and the msaccess code was that i was passing the db name and the access file password in the logon info in foreach loop of crtables.

    Regards,

    Kiran Jain

    PS: i am using Crystal reports from Visual studio 2005 and sql server 2005

    private void FormReportDailyCollection_Load(object sender, System.EventArgs e)

    {

    string myQuery = "Select min(P_DATE) as [DATE] from PAYMENTS where [P_COMP_ID] = " + GlobalVariable.CompanyIDGlobal;

    OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myQuery,GlobalVariable.dbConnectionGlobalObject);

    DataTable myDataTable = new DataTable();

    myDataAdapter.Fill(myDataTable);

    if (myDataTable.Rows.Count!=0)

    {

    DataRow myDatarow=myDataTable.Rows[0];

    this.dateTimePickerFromDate.Text=Convert.ToDateTime(myDatarow["DATE"].ToString()).ToShortDateString();

    }

    else

    {

    MessageBox.Show("There are no Payment Transactions!!!");

    }

    }

    private void buttonGo_Click(object sender, System.EventArgs e)

    {

    string methodName = this.GetType().FullName + ".buttonGo_Click(object,System.EventArgs)";

    try

    {

    Cursor.Current= Cursors.WaitCursor;

    ReportDocument crReport = new CrystalReportDailyCollection();

    TableLogOnInfo myLogonInfo= new TableLogOnInfo();

    ParameterFields paramField= new ParameterFields ();

    crystalReportViewerDailyCollection.ParameterFieldInfo=AddParameter("FROMDATE",this.dateTimePickerFromDate.Text,paramField);

    crystalReportViewerDailyCollection.ParameterFieldInfo=AddParameter("TODATE",this.dateTimePickerToDate.Text,paramField);

    crystalReportViewerDailyCollection.ParameterFieldInfo=AddParameter("CompID",GlobalVariable.CompanyIDGlobal.ToString() ,paramField);

    foreach (Table crTable in crReport.Database.Tables)

    {

    myLogonInfo.ConnectionInfo.UserID = GlobalVariable.SQLUserName;

    myLogonInfo.ConnectionInfo.Password = GlobalVariable.SQLPassword;

    myLogonInfo.ConnectionInfo.ServerName = GlobalVariable.SQLServerName;

    myLogonInfo.ConnectionInfo.DatabaseName = GlobalVariable.SQLDBName;

    crTable.ApplyLogOnInfo(myLogonInfo);

    }

    crReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait;

    crReport.PrintOptions.PaperSize = PaperSize.PaperA4;

    crystalReportViewerDailyCollection.ReportSource = crReport;

    Cursor.Current= Cursors.Default;

    }

    catch(Exception exceptionObject)

    {

    GlobalVariable.errorHandlerGlobalObject.LogMessage("Exception occurred at: " + methodName);

    throw exceptionObject;

    }

    }

    private ParameterFields AddParameter (string paramName, string paramValue,

    ParameterFields paramFields)

    {

    ParameterField paramField= new ParameterField ();

    ParameterDiscreteValue paramDiscreteValue = new

    ParameterDiscreteValue ();

    ParameterValues paramValues = new ParameterValues ();

    // Set the name of the parameter to modify.

    paramField.ParameterFieldName = paramName;

    // Set a value to the parameter.

    paramDiscreteValue.Value = paramValue;

    paramValues.Add (paramDiscreteValue);

    paramField.CurrentValues = paramValues;

    // Add the parameter to the ParameterFields collection.

    paramFields.Add (paramField);

    return paramFields;

    }

    Friday, December 26, 2008 4:57 PM

Answers

  • Kiran Jain said:

    thanks Robert, I have Posted the same



    The problem is now Solved the Problem is with my computer, when i compile from my computer the server name cant be changed dynamically. where as when i compiled the same application from another computer, i  was able to change the server name dynamically..

    Kiran Jain
    • Marked as answer by Kiran Jain Friday, January 2, 2009 9:04 AM
    Friday, January 2, 2009 9:04 AM

All replies

  • Hi Kiran,

    this is the forum for the Microsoft Reporting Services based Report Viewer control.   For Crystal questions, please try the following forum: http://social.msdn.microsoft.com/Forums/en-US/vscrystalreports/threads/

    Thanks,
    Robert
    Robert Bruckner; http://blogs.msdn.com/robertbruckner; This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, December 30, 2008 5:42 PM
    Moderator
  • thanks Robert, I have Posted the same
    Wednesday, December 31, 2008 8:25 AM
  • Kiran Jain said:

    thanks Robert, I have Posted the same



    The problem is now Solved the Problem is with my computer, when i compile from my computer the server name cant be changed dynamically. where as when i compiled the same application from another computer, i  was able to change the server name dynamically..

    Kiran Jain
    • Marked as answer by Kiran Jain Friday, January 2, 2009 9:04 AM
    Friday, January 2, 2009 9:04 AM