Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Database Logon Fail Post Reply Post New Topic
<< Prev Page  of 2
Author Message
rushelp
Newbie
Newbie


Joined: 25 Jun 2012
Online Status: Offline
Posts: 19
Quote rushelp Replybullet Posted: 03 Aug 2012 at 8:04am
I do have one crystal report viewer which shows all the clients by their ID. Once I open the program, it asks which ID I want to show the report for in the viewer. I select all of them. However, the view and the files that getting generated into pdf are not tied together. I don't know what to do then.


What I'm doing with reports for each checkbox is getting the path.

private void save_Click(object sender, EventArgs e)
{
var reportPaths =
from ctrl in panel1.Controls.OfType<CheckBox>()
let reportPath = ctrl.Tag as string
where ctrl.Checked && !string.IsNullOrEmpty(reportPath)
select reportPath;
foreach (string reportPath in reportPaths)
{
    ExportReport(reportPath);
}
}

Then this is how I export.

private void ExportReport(string reportPath)
        {
            //uploads crystal file
            string fileName = Path.GetFileName(reportPath);
            ReportDocument report = new ReportDocument();
            report.Load(reportPath);
            report.SetDatabaseLogon("user", "pass", "server", "database");
            
           report.Refresh();
            //file path where pdf's are stored
            string destination = @"...\convertedpdf\{0}_DetailedCallReport_{1:yyyyMM}.pdf";
       
            DirectoryInfo tempPathPdfDirName = Directory.CreateDirectory(Path.Combine(System.IO.Path.GetTempPath(),
            Guid.NewGuid().ToString()));
            string tempPdfFileName = Path.Combine(tempPathPdfDirName.FullName, destination);
            try
            {
               ExportOptions options = report.ExportOptions;
               options.ExportDestinationType = ExportDestinationType.DiskFile;
               options.ExportFormatType = ExportFormatType.PortableDocFormat;
               options.DestinationOptions = new DiskFileDestinationOptions()
               {
                    DiskFileName = String.Format(
                     @destination,
                     
                     System.IO.Path.GetFileNameWithoutExtension(fileName),
                     DateTime.Now.AddMonths(-1))
              

                     
               };
               options.FormatOptions = new PdfRtfWordFormatOptions();
               report.Export();
               report.Close();
               report.Dispose();

            }
            catch (Exception ex)
            {
               MessageBox.Show(ex.ToString());
            }

        }

Any help, on how I can bypass that parameter?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 06 Aug 2012 at 3:12am
In the report, try setting the parameter as optional and giving it a default value.
 
-Dell
IP IP Logged
awardhan
Newbie
Newbie


Joined: 09 Dec 2012
Online Status: Offline
Posts: 2
Quote awardhan Replybullet Posted: 09 Dec 2012 at 4:40pm
Hi,

I am actually having a similar problem.
We are using cr for vs.net2010 (14.0.2000.0) and SQLExpress 2008r2 database.

The database connection seems to work fine in the following environment:
1. Dev
2. Old production box
And also for a brand new report.(apparently I can't afford to rewrite all the reports)

However, this doesn't work in the new production environment. I have checked if sql native client is installed, and it has.

I tested the database connectivity using the following code:

ReportDocument rd = new ReportDocument();
rd.Load(reportPath);
rd.SetParameterValue("@invoiceID", invoiceID);

ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = server;
myConnectionInfo.UserID = username;
myConnectionInfo.Password = password;
myConnectionInfo.DatabaseName = database;

rd.DataSourceConnections.Clear();           
Tables tbls = rd.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in tbls)
{
TableLogOnInfo info = tbl.LogOnInfo;
info.ConnectionInfo = myConnectionInfo;
tbl.ApplyLogOnInfo(info);
bool b = tbl.TestConnectivity();
if (!b)
{
throw new Exception("main connection failed");
}
}

And it always got into "main connection failed".
I am not sure if I miss anything...
Any help would be appreciated,

Thank you,

Edited by awardhan - 09 Dec 2012 at 5:11pm
IP IP Logged
awardhan
Newbie
Newbie


Joined: 09 Dec 2012
Online Status: Offline
Posts: 2
Quote awardhan Replybullet Posted: 09 Dec 2012 at 5:24pm
Please ignore my message.

I had to change from (local) to ".\sqlexpress".
It seems like I have to use ".\sqlexpress", for sql express it doesn't work for (local).

Thank you,
IP IP Logged
<< Prev Page  of 2
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.015 seconds.