- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHi,
I'm trying to use a crystal report with .NET 2005 with C# but experiencing some problems
when trying to connect to the database to pull the data for the report. The code below
shows how I implemented the connection procedures. The problem is the code is unbale to
change which database the report connects to and defaults to the connection that was used
to design the report. The ApplyLogonToReport method does not seem to work. Can anyone help
me with the problem? The report calls a stored procedure to get the data.
private void cmdRun_Click(object sender, EventArgs e)
{
try
{
SqlString user; SqlInt32 loccode;
report = new RptTransactionDetailsCpy()
SqlConnectionStringBuilder
report.SetDatabaseLogon(co
ConnectionInfo info = new ConnectionInfo();
info.AllowCustomConnection
info.UserID = constr.UserID;
info.Password = constr.Password;
info.ServerName = constr.DataSource;
info.DatabaseName = constr.InitialCatalog;
info.IntegratedSecurity = constr.IntegratedSecurity;
foreach(ReportObject obj in report.ReportDefinition.Re
{
if(obj.Kind == ReportObjectKind.Subreport
{
SubreportObject subObj = (SubreportObject)obj;
ReportDocument rd = report.OpenSubreport(subOb
ApplyLogonToReport(rd, constr.DataSource, constr.InitialCatalog, constr.UserID, constr.Password, constr.IntegratedSecurity)
}
}
}
catch(Exception ex){}
}
public bool ApplyLogonToReport(ReportD
{
int i = 0;
TableLogOnInfo logonInfo = new TableLogOnInfo();
foreach(CrystalDecisions.C
{
logonInfo = table.LogOnInfo;
logonInfo.ConnectionInfo.A
logonInfo.ConnectionInfo.S
logonInfo.ConnectionInfo.D
logonInfo.ConnectionInfo.I
if(!sspi)
{
logonInfo.ConnectionInfo.U
logonInfo.ConnectionInfo.P
}
table.ApplyLogOnInfo(logon
if(sspi)
{
rd.DataSourceConnections[s
}
else
{
rd.DataSourceConnections[s
}
i++;
if(!table.TestConnectivity
{
return false;
}
}
return (true);
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: TMWSIYPosted on 2007-06-15 at 08:11:09ID: 19292536
I created a simpler app and the code below allows me to change the server and database by changing the values of serverName and dbName.
fileOptions = new DiskFileDestinationOptions (); ports.Engi ne.Table table; i++) o[i, 0]);
LogOn);
Value("mon th1", DateTime.Now.AddDays(-1).M onth.ToStr ing()); Value("yea r1", DateTime.Now.AddDays(-1).Y ear.ToStri ng());
No sub reports or sspi...
HTH
ReportDocument workingReport = new ReportDocument();
DiskFileDestinationOptions
ExportOptions exportOptions = new ExportOptions();
Database db;
Tables tables;
CrystalDecisions.CrystalRe
TableLogOnInfo tableLogOn = new TableLogOnInfo();
ConnectionInfo cnInfo = new ConnectionInfo();
public void ExportReports(ref CustomClass.Logger log)
{
try
{
for (int i = 0; i <= fileInfo.GetUpperBound(0);
{
log.LogMsg("Creating Crystal Report as " + fileInfo[i, 0]);
workingReport.Load(fileInf
log.LogMsg("Setting up Connection info");
cnInfo.ServerName = serverName;
cnInfo.DatabaseName = dbName;
cnInfo.UserID = userName;
cnInfo.Password = password;
db = workingReport.Database;
tables = db.Tables;
log.LogMsg("Acquiring DB Table Perms");
for (int j = 0; j < tables.Count; j++)
{
table = tables[j];
tableLogOn = table.LogOnInfo;
tableLogOn.ConnectionInfo = cnInfo;
table.ApplyLogOnInfo(table
}
log.LogMsg("Setting report params");
workingReport.SetParameter
workingReport.SetParameter
//Export report
ExportReport(ref workingReport, ref log, fileInfo[i, 1].ToString());
workingReport.Close();
}
}
catch (Exception ex)
{
log.LogError("Error durring ExportReports().\r\n" + ex.ToString());
}
finally
{
workingReport = null;
fileOptions = null;
exportOptions = null;
db = null;
tables = null;
table = null;
tableLogOn = null;
cnInfo = null;
}
}