Solved

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

Posted on 2006-06-29
3
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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