Solved

SQLConnection not working for Crystal Reports windows form - Getting a login dialog box during runtime

Posted on 2006-06-29
3
587 Views
Last Modified: 2008-01-09
Two Issues

Issue 1.
Why does the Database Login dialog box pop up during runtime? The dialog box displays:

Table name: ADPFile
Server Name: Myserver
Database: MyDB
Login ID: MyUID
Password: <this is blank even though I provided it in the SQLConnection string>

Issue 2.
When I type in the password and click the Finish button, it display the report as a dump of the SQL Server View (ADPFile) NOT as the SELECT query that I want to pass.

Any help will be greatly appreciated. It is hard to find good documentation.  

IDE and Crystal Version - VS2003 Pro and Crystal Reports 9

Code Specifics -

private void Form4_Load(object sender, System.EventArgs e)
      {
                  
            ADPReport rpt = new ADPReport();
                        
            SqlConnection cn = new SqlConnection("Data Source=Myserver;Database=myDB;uid=MyUID;pwd=Hello");
                        
            SqlDataAdapter ADPda = new SqlDataAdapter("SELECT CEMPID, UTADPID, CEMPNAME, PAYRATE, COALESCE(EXPAMT,' ')AS EXPAMT, REGHRS, OTHRS,PAYTYPE FROM ADPFile WHERE (PAYTYPE = 1 AND EXPAMT IS NOT NULL) OR (PAYTYPE = 2) ORDER BY PAYTYPE, CEMPNAME", cn);
      
      DataSet ADPds = new DataSet();
      ADPda.Fill(ADPds, "Payroll");
                  
      rpt.SetDataSource(ADPds);
      crystalReportViewer1.ReportSource = rpt;
            
      }

Thanks,

Brad Swihart
Trigon IT
0
Comment
Question by:Trigon
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
MyersA earned 500 total points
ID: 17013965
Hi Trigon,

I also had the same problem, and I had trouble finding info on this on the Web. The problem (in my case, a webpage with CrystalReportViewer control - VS2005) is that you need to "tell" Crystal Reports what the username/password is.  Here's the code that I used:

private void Page_Init(object sender, EventArgs e)
{
  ConnectionInfo connectionInfo = new ConnectionInfo();
  connectionInfo.ServerName = "SERVER";
  connectionInfo.DatabaseName = "DBNAME";
  connectionInfo.UserID = "user";
  connectionInfo.Password = "pass";
  string reportPath = Server.MapPath("CrystalReport.rpt");
  CrystalReportViewer.ReportSource = reportPath;
  SetDBLogonForReport(connectionInfo);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo)
{
  TableLogOnInfos tableLogOnInfos = CrystalReportViewer.LogOnInfo;
  foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
  {
    tableLogOnInfo.ConnectionInfo = connectionInfo;
  }
}

You can find info here:
http://msdn2.microsoft.com/en-us/library/ms227471.aspx

VM
0
 

Author Comment

by:Trigon
ID: 17030820
Thanks for the quick reply. I'm out of the office and won't be back until July 6. I'll give the code a whirl and let you no the results by Friday.
0
 

Author Comment

by:Trigon
ID: 17054036
I accepted this solution with full credit because it led me to a lot of details that I needed to understand how VS2003 works with CR9.

However, I did not use the specific solution provided by MeyersA. Instead, I found a really concise solution in the SAMS Publishing book "Teach Yourself Visual Studio .NET 2003 in 21 Days" by Jason Beres. My code closely resembles his code in the chapter entitled "Day 18 Using Crystal Reports" and it works very well. I'm not sure I should copy the code here without violating copywrite laws so I'll suggest to anyone that needs a little more handholding to check this book out.

Thanks MeyersA for getting me to the final solution. I studied your code and followed the link you provided. Since I am building a windows form instead of a webform, I had to do additional searches. It is not easy to find good instructions but Beres' book really helped and got right to the point.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now