Is this the same question
http://www.experts-exchang
mlmcc
Main Topics
Browse All TopicsHere's my question:
We have an oracle server with four different databases that represent four different environments. (MAN_TEST, MAN_PROD, MAN_DEV, MAN_PILOT). I have a Crystal Report web application that displays a report that pulls data from the MAN_PILOT environment on this oracle database. I want to be able to change the data source programmatically to one of the other databases (like MAN_DEV). IS there anyway to do this? I've heard about people applying logoninfo to each table and all that, but nothing seems to work for me. It always tries to connect using the original datasource defined during the initial report design. What should I do?
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.
Is this the same question
http://www.experts-exchang
mlmcc
Well, I've tried several different ways. At first I figured the only thing I had to do was change the ReportDocument.SetDatabase
using System;
using System.Data;
using System.Collections.Special
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
using System.IO;
using CrystalDecisions.CrystalRe
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSou
public partial class RunReport : System.Web.UI.Page
{
private string _reportPath = ConfigurationManager.AppSe
protected string strSelectionFormula = "";
protected string dbName = "";
protected string dbUser = "";
protected string dbPass = "";
protected string serverName = "";
/// <summary>
/// Loads a crystal report file into the current aspx page. Accepts query string arguments: ReportID, DB, dbUsername
/// and dbPassword. Only ReportID is required.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
//call method to pull database information from web.config for each specific environment
GetDbInfo();
try
{
//load the report file specified in the query string
doc.Load(Server.MapPath(_r
}
catch
{
throw new System.Exception("Could not load the requested report file. Please specify a report file in the query string.");
}
//call the method to apply login information to each table in the report
FixDatabase(doc);
//set database login information for the entire report object
doc.SetDatabaseLogon(dbUse
//load selection formula from query string, or default it to nothing
try
{
strSelectionFormula = this.Request.QueryString["
}
catch
{
strSelectionFormula = "";
}
finally
{
doc.DataDefinition.RecordS
}
Viewer.ReportSource = doc;
}
/// <summary>
/// Dissects the query string for user supplied database information.
/// </summary>
protected void GetDbInfo()
{
// check for a user supplied database name through query string
try
{
//create a new name value collection to collect database info from web.config
NameValueCollection dataBaseInfo = new NameValueCollection();
//get database name from query string
dataBaseInfo = (NameValueCollection)Confi
//gather db name, db query user, db query pass
dbUser = dataBaseInfo.Get("User").T
dbPass = dataBaseInfo.Get("Pass").T
dbName = dataBaseInfo.Get("Name").T
serverName = dataBaseInfo.Get("ServerNa
}
catch
{
throw new System.Exception("Error loading database information. Please specify which database to use in the query string.");
}
}
private void FixDatabase (ReportDocument report)
{
foreach (CrystalDecisions.CrystalR
{
TableLogOnInfo logOnInfo = table.LogOnInfo;
if (logOnInfo != null)
{
table.LogOnInfo.TableName = table.Name;
table.LogOnInfo.Connection
table.LogOnInfo.Connection
table.LogOnInfo.Connection
table.LogOnInfo.Connection
table.ApplyLogOnInfo(table
}
}
//call this method recursively for each subreport
foreach (ReportObject reportObject in report.ReportDefinition.Re
{
if (reportObject.Kind == ReportObjectKind.Subreport
{
FixDatabase(report.OpenSub
}
}
}
}
I tried the code above and it actually keeps displayin the original data that the report was bound to. I added ReportViewer.RefreshReport
Here is my code. for now everfything is hard coded until I get the proof of concept working. Also I moved the ApplyTableInfo to the beginning of the loop because I noticed that if I used it at the end my connection data was getting reset.
Also another thing I noticed happening is that when I look at the table's LogOnInfo.ConnectionInfo the
password is an empty string while in the report I definately set it. So I am not sure why does it coem inlike that. Maybe that is the reason that even after I specify a password for the new connection it does not work...
Business Accounts
Answer for Membership
by: mlmccPosted on 2007-07-11 at 13:17:11ID: 19466357
How are you trying to change the connection?
mlmcc