Changing the database location drops owner schema - c#

We have hundreds of Reports created in 8.0.1.0 (I know they are old).
We created a Visual Studio 2010 C# application to run these reports. It's a Windows App. Had some trouble with the Web App.
The reports are all saved under the PROD environment.
We are working in a TEST environment.
We are using an Oracle environment and all the reports use the Oracle Server connection.
When we run the reports through C# we go ahead and change all the database locations to our TEST environment. When this happens the "Owner" (schema) information is dropped. The report fails with a 942 error.
Now if we don't change the database, keep it as PROD, everything works perfectly. It seems that by changing the database the schema information is dropped.
Any ideas. I've been searching around and can't find a solution.
Snippet of code:
connectionInfo.DatabaseName = "";
connectionInfo.ServerName = <SERVER>;
connectionInfo.UserID = <USER>;
connectionInfo.Password = <PWORD>;
foreach (Table crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = connectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
// if you wish to change the schema name as well, you will need to set Location property as follows:
//crTable.Location = "<SCHEMA>." + crTable.Name;
}
I've tried to set the crTable.Location but the program locks up. So not sure what to do.

In the past we successfully changed connection parameters by doing this:
CrystalDecisions.Shared.TableLogOnInfo info = document.Database.Tables[iTable].LogOnInfo.Clone() as CrystalDecisions.Shared.TableLogOnInfo;
info.ConnectionInfo.ServerName = <SERVER>;
info.ConnectionInfo.DatabaseName = "";
info.ConnectionInfo.UserID = <USER>;
info.ConnectionInfo.Password = <PASSWORD>;
document.Database.Tables[iTable].ApplyLogOnInfo(info);
where document is CrystalDecisions.CrystalReports.Engine.ReportDocument.

Fixed it by doing this:
connectionInfo.DatabaseName = "";
connectionInfo.ServerName = <SERVER>;
connectionInfo.UserID = <USER>;
connectionInfo.Password = <PWORD>;
foreach (Table crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = connectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
// if you wish to change the schema name as well, you will need to set Location property as follows:
//crTable.Location = "<SCHEMA>." + crTable.Name;
crTable.Location = "<SCHEMA>." + crTable.LogOnInfo.TableName;
}
I was setting the Location incorrectly. Thanks for your help!

Related

How do I connect Crystal reports to multiple database?

I have a webpage which has a drop-down. In the drop-down there is a list of databases from a server. On selecting the drop-down document numbers are shown and we can click and generate crystal report.
My problem is I have given data-source for one database in the crystal report. Suppose I select other databases. How can I connect to the report for multiple databases?
Any inputs will be greatly appreciated.
Are you using CR designer or Visual Studio to make your reports? Because there is a connection section in the field explorer window. Generally, it is not recommend to connect to multiple DB. Even if you are using for example 2 or more stored procedures for your report, you can complicate your life if they don't have a common key.
The below is what we use, it should work for you. Basically you have to make sure that for every table the report accesses (or command, or view, etc.), the connection is set. I'm not aware of a way to set it only on the main report.
// create a ReportDocument
using (ReportDocument reportDoc = new ReportDocument())
{
reportDoc.Load(path); // path to your .rpt file
// get the connection string you want to use
SqlConnectionStringBuilder conInfo = new SqlConnectionStringBuilder("<your connection string>");
Tables crTables = reportDoc.Database.Tables;
int tablecounter = 0;
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
CrystalDecisions.Shared.TableLogOnInfo logonInfo = crTable.LogOnInfo;
logonInfo.ConnectionInfo = new ConnectionInfo()
{
DatabaseName = conInfo.InitialCatalog,
ServerName = conInfo.DataSource
};
if (conInfo.IntegratedSecurity)
{
logonInfo.ConnectionInfo.IntegratedSecurity = true;
}
else
{
logonInfo.ConnectionInfo.UserID = conInfo.UserID;
logonInfo.ConnectionInfo.Password = conInfo.Password;
}
crTable.ApplyLogOnInfo(logonInfo);
}
}

published reports don't work - Database logon failed Error

I am developing a simple web app that has 3 reports created on VS 2013, for some reason those reports run fine from developer mode, but when I publish the website they give me "Database logon failed" Error. What could be causing this? VS is installed on the same server that I am publishing the reports. I have created a local admin user with exactly the same info as the ODBC connection logon user for IIS authentication, but still no luck.
below is my code:
public partial class OpenWOsWebForm : System.Web.UI.Page
{
ConnectionInfo EPAKconnectionInfo = new ConnectionInfo();
protected void SetConnectionInfo()
{
EPAKconnectionInfo.ServerName = ConfigurationManager.AppSettings["EPAK_SERVER_NAME"];
EPAKconnectionInfo.UserID = ConfigurationManager.AppSettings["EPAK_USER_NAME"];
EPAKconnectionInfo.Password = ConfigurationManager.AppSettings["EPAK_PASSWORD"];
}
private void Page_Init(object sender, EventArgs e)
{
ReportDocument report = new ReportDocument();
report.Load("C:\\Delray Beach\\Delray Beach\\Reports\\OpenWOsReport.rpt");
SetConnectionInfo();
TableLogOnInfo crTableLogoninfo = new TableLogOnInfo();
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in report.Database.Tables)
{
crTableLogoninfo = CrTable.LogOnInfo;
crTableLogoninfo.ConnectionInfo = EPAKconnectionInfo;
CrTable.ApplyLogOnInfo(crTableLogoninfo);
}
foreach (ReportDocument subreport in report.Subreports)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in subreport.Database.Tables)
{
crTableLogoninfo = CrTable.LogOnInfo;
crTableLogoninfo.ConnectionInfo = EPAKconnectionInfo;
CrTable.ApplyLogOnInfo(crTableLogoninfo);
}
}
OpenWOsViewer.ReportSource = report;
OpenWOsViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
}
}
Thanks
Besides "Database logon failed", does it say "Unable to connect: incorrect log on parameters"?
If so, try this: https://stackoverflow.com/a/24578304/2248943
And try these:
kill the asp.net proccess (w3wp.exe or aspnet.exe) (it will
restart) .
if you are using a XSD file, check it's location path in
the RPT, try to "set location" again; if it does not work, try to remove the tables and include them ok (this will be hard-working).
I faced this problem many times and each case was solved by one of these actions.
In my case the problem was that on IIS Application Pools/ my web app/ Advanced Settings the 32 bit Applications was disable and I wasn't including on my project the folder aspnet_client where crystal run-times files are storage, so the time I was publishing the app, those files wren't transferred. Once I enabled the connection and included that folder the issue got resolved.

why crystal report is getting all records even with RecordSelectionFormula set?

I am using the following code for loading crystal reports.
ConnectionInfo crconnectioninfo = new ConnectionInfo();
ReportDocument cryrpt = new ReportDocument();
TableLogOnInfos crtablelogoninfos = new TableLogOnInfos();
TableLogOnInfo crtablelogoninfo = new TableLogOnInfo();
Tables CrTables;
crconnectioninfo.ServerName = "localhost";
crconnectioninfo.DatabaseName = "dbclients";
crconnectioninfo.UserID = "ssssssss";
crconnectioninfo.Password = "xxxxxxx";
cryrpt.Load(Application.StartupPath + "\\rpts\\" + dealerInfo.ResourceName);
CrTables = cryrpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtablelogoninfo = CrTable.LogOnInfo;
crtablelogoninfo.ConnectionInfo = crconnectioninfo;
CrTable.ApplyLogOnInfo(crtablelogoninfo);
}
cryrpt.RecordSelectionFormula = getCustInfoRptSelection();
cryrpt.Refresh();
allReportViewer.ReportSource = cryrpt;
getCustInfoRptSelection() is getting a specific client
but the report shows all the clients at first time and when i close the report and open it again it shows the correct record.
so basicly i have to open the report twice to get the correct data though the getCustInfoRptSelection() results is not changing.
and in this case the RecordSelectionFormula =" {dealer.dealer_type_id}=2 and {dealer.DEALER_NAME} like 'Mark stall X'"
I had the exact same problem, and I found this answer on a SAP website that worked
Expand Form1.vb|cs to show Form1.Designer.vb|cs and double-click it to show its code
Find where the initial crystalReportViewer1 properties are set in the the InitializeComponent method
Comment out or delete the following two lines:
this.crystalReportViewer1.SelectionFormula = ""
this.crystalReportViewer1.ViewTimeSelectionFormula = ""
Apparently this was something that was added in one of their newer service packs, as this problem didn't start happening until after I upgraded the Crystal Reports framework for .Net
This one nailed it.
Locate your Windows Form that contains the CrystalReportViewer Control.
Normally, your Windows Form has Resx file and designer file
Example:
Open the Designer file:
Delete the 2 lines below:
This I think is a bug.
I am using VS2015 VB.NET.
It worked!

C# Crystal Reports Login fails on Windows XP

I have written this code with the help of other programmers. This code works perfectly when running on Windows 7 but when I install the program on Windows XP the log-on fails. I have installed .Net Framework 4.0 and CRforVS_13_0_3 of Crystal Reports on the Windows XP machine.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
label2.Text = Convert.ToString(BAssistencia.nroo);
ReportDocument segredo = new ReportDocument();
segredo.Load(#"C:/Relatorios/CrystalReport3.rpt");
ParameterField pf1 = new ParameterField();
ParameterFields pf1s = new ParameterFields();
ParameterDiscreteValue pdv = new ParameterDiscreteValue();
TableLogOnInfo tabla = new TableLogOnInfo();
TableLogOnInfos tablas = new TableLogOnInfos();
ConnectionInfo infocon = new ConnectionInfo();
Tables crtables;
infocon.ServerName = "server";
infocon.DatabaseName = "database";
infocon.UserID = "user";
infocon.Password = "password";
infocon.IntegratedSecurity = false;
crtables = segredo.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table crtable in crtables)
{
tabla = crtable.LogOnInfo;
tabla.ConnectionInfo = infocon;
crtable.ApplyLogOnInfo(tabla);
}
pf1.Name = "#pedido";
pdv.Value = label2.Text;
pf1.CurrentValues.Add(pdv);
pf1s.Add(pf1);
crystalReportViewer1.ParameterFieldInfo = pf1s;
crystalReportViewer1.ReportSource = segredo;
What am I doing wrong???
A few links, the first one are extension methods that I've written that I use with Crystal (on XP, Vista and 7 along with Server 2003, 2008 and they work there).
Crystal Reports extension methods for .Net:
http://www.blakepell.com/Main/BlogEntry.aspx?EntryID=e2fcdcf9-312e-4911-8572-20178c94660b
The second one here has a different issue but in the end (before my rant) I have some info about gotchas swapping out connections at runtime.
http://www.blakepell.com/Blog/?p=15
The code provided above has worked for me in all of my environments. Now, in your case, you'll also want to make sure that the XP box has access to the database server outside of Crystal also (no firewalls blocking, the server isn't denying it access, no ACL's in place that are stopping network routing, etc). Over the years I have found swapping connections out with Crystal to be very particular.

Crystal Reports not chaging the server programatically

I'm developing a local app with friends and we're using svn, but we have crystal reports, but it saves the last server used by one of my friends when doing the commit. I tried changing the server programatically using this piece of code, but it didn't work :S
*UPDATE: it seems that the .rpt keeps a history of the server names, and somehow doesn't seem to clear the list, so my friends computer "\sqlexpress" is still there, and I can't seem to clear it :S"
string nombre = WindowsIdentity.GetCurrent().Name.ToString().Split('\\')[1];
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables ;
//cryRpt.SetDatabaseLogon(string.Empty,string.Empty, nombre + "\\sqlexpress","trupp");
cryRpt.Load(FinalPath);
crConnectionInfo.ServerName = nombre + "\\sqlexpress";
crConnectionInfo.IntegratedSecurity = true;
crConnectionInfo.UserID = string.Empty;
crConnectionInfo.Password = string.Empty;
crConnectionInfo.DatabaseName = "trupp";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
You need to make a call to clear the existing connections from the report before setting the new ones.
cryRpt.Load(FinalPath);
// After loading report clear all datasourceconnections
cryRpt.DataSourceConnections.Clear();
// Now you can set new datasourceconnections
crConnectionInfo.ServerName = nombre + "\\sqlexpress";
Sometimes Crystal Reports can be a pain so if for some reason the above doesn't work you can always just set the server name on the existing connection embedded in the report.
cryRpt.DataSourceConnections[0].SetConnection(nombre + "\\sqlexpress", "trupp", true);
It's a pain in the neck, eh?
If you and your friends are using the same make and model of database table server, you might try putting an entry in each developer machine hosts file to create a local hostname alias, or if your development data bases are all on your own machines, use localhost.
If you use ODBC, you can all create your own ODBC entries with the same name and use those.

Categories