Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

crystal report logon problem

Posted on 2010-09-05
10
Medium Priority
?
2,365 Views
Last Modified: 2012-05-10
dear experts

ive used crystal reports in my asp.net c# web project

the code for report has been writte in c# [please see code section]

this works fine when the report is first loaded

however, upon drill-down it is not using the username, password given via c# code and thus report gives error

i know what the problem is, but don't know how to solve it

how do i make the report use the username/password/server/database provided to it using c# upon drill-downs as well?


error message:
Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Login failed for user 'username'. SQL State: 42000 Native Error: Error in creating new data source. Error in File C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\BrokerageSegregated {E82F4CE2-A130-45CD-8C9B-197A31AC0F23}.rpt: Unable to connect: incorrect log on parameters
ReportDocument rpt = new ReportDocument();

rpt.Load(Server.MapPath("BrokerageSegregated.rpt"));

CrystalReportViewer1.ReportSource = rpt;

rpt.SetDatabaseLogon(booya.username, booya.password, booya.server, booya.database);

Open in new window

0
Comment
Question by:RakeshBhandari
[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
  • 6
  • 2
  • 2
10 Comments
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 33609096
Here i added sample code for bind crystal from DB
CrystalDecisions.CrystalReports.Engine.ReportDocument oReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

[] DoCRLogin = new[];
public void DoCRLogin(ref CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt)
{
	ApplyCRLogin _applyLogin = new ApplyCRLogin();


	// use ApplyLogin object to apply login info to all tables in CR object
	_applyLogin._dbName = "Northwind";
	_applyLogin._passWord = "CrystalUser";
	_applyLogin._serverName = "(local)";
	_applyLogin._userID = "CrystalUser";
	_applyLogin.ApplyInfo(ref oRpt);


	// clean up
	_applyLogin = null;
}



public class ApplyCRLogin
{
	public string _dbName;
	public string _serverName;
	public string _userID;
	public string _passWord;
	public void ApplyInfo(ref CrystalDecisions.CrystalReports.Engine.ReportDocument _oRpt)
	{
		CrystalDecisions.CrystalReports.Engine.Database oCRDb = _oRpt.Database;
		CrystalDecisions.CrystalReports.Engine.Tables oCRTables = oCRDb.Tables;
		CrystalDecisions.CrystalReports.Engine.Table oCRTable = default(CrystalDecisions.CrystalReports.Engine.Table);
		CrystalDecisions.Shared.TableLogOnInfo oCRTableLogonInfo = default(CrystalDecisions.Shared.TableLogOnInfo);
		CrystalDecisions.Shared.ConnectionInfo oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
		oCRConnectionInfo.DatabaseName = _dbName;
		oCRConnectionInfo.ServerName = _serverName;
		oCRConnectionInfo.UserID = _userID;
		oCRConnectionInfo.Password = _passWord;
		foreach ( oCRTable in oCRTables) {
			oCRTableLogonInfo = oCRTable.LogOnInfo;
			oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
			oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);


		}


	}


}

Open in new window

0
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 33609100
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33609117
@dhansmani: that's a lot of changes in the code

is there a simpler solution
the report DOES work fine when it first loads... meaning it is reading the username, password values passed to it
i want to make it so so that it does that even on drill-down!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:frankhelk
ID: 33610519
Not yet looked into my old reports apps, but there's some faint memory of similar problems.

As far as I remember, the subreport that's used wile drilling down uses its own database connection, thus needing to pass it its ofw set of credentials - they're not inherited. You'll have to get the subreport's report object and pass it the credentials in the same way you do for the master report.

I faintly remember that there's some kind of collections of subreports, so you might write some generic algorithm to distribute the credentials down the tree of sub(^n)report tree.

Sorry for not supplying ready code  =;-)
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33614873
dear frankhelk,

your comment does help understand the problem a bit
however, im still lost as to how to go on about solving it

it would be really appreciated and a great help to me if you could give me some coding pointers to help solve my problem

0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33614996
@ dhansmani

i do not understand how do i apply the code snippet you've given
can you elaborate a little, please?
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33616022
i have solved this problem on my own now
0
 
LVL 2

Accepted Solution

by:
RakeshBhandari earned 0 total points
ID: 33616035
specifying database logon info to the crystalviewer solved my problem
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 33616318
Ok ... I've digged into that old code, not written by myself ...

Unfortunately that code is somewhat :) complicated (much ado with virtual thingies and templates and such things who make every explanation a bloody mess).

I've digged a bit into the object browser, and found something more shot - it might point you into the right direction:

public virtual CrystalDecisions.CrystalReports.Engine.Subreports Subreports { get; }
    Member of CrystalDecisions.CrystalReports.Engine.ReportDocument
Summary:
Subreports. Gets the Subreports object.


That member Subreports in the class ReportDocument is a collection of SubReport objects (see doc's) that can be treated as ReportDocument objects. You can loop through them with a foreach construct and assign each of them the database connection credentials.

The credentials are not inherited from the main ReportDocument, probably because you might possibly want to drill down into an entire different database, only filtered by criteria handed down from the main document - so every Subreport needs to get its own connection.

I've not worked with that for some time now, so I'm not fluent enough to explain every aspect of it, but if you fiddle a bit with that, it should not be that difficult.
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 33616536
i appreciate every effort you've taken, frankhelk, but thankfully, the problem is solved now. i just specified the logon info to the crystalviewer. many thanks
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

730 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