Crystal Report Logon Failed Problem - c#

I am using....
Framework 3.5 C# Visual Studio 2008 and web based application
I have created reports using Dataset i.e. my service gives me data set and I bind that dataset with report.
But sometimes CR viewer started popping up error "Logon Failed" with login box with dataset name filled in login information.
I am searching for its solution for quite some time but did not fine any suitable answer to this.

This error is unfortunately ambiguous because it is the generated error for dozens of unrelated problems. In this case, the "Logon failed" is likely due to an occasional schema mismatch.
The DataSet object can contain hierarchical data. If your service is returning a DataSet containing hierarchical data, and some of the children are missing, then its schema has effectively changed.
There are several ways to ensure that the DataSet has a matching schema. If you are serializing objects into XML and then generating the DataSet from that XML, then a simple way to achieve a consistent schema is to change your code from:
reportData.ReadXml(new MemoryStream(Encoding.UTF8.GetBytes(reportXml)));
to
reportData.ReadXmlSchema(schemaPath);
reportData.ReadXml(
new MemoryStream(Encoding.UTF8.GetBytes(reportXml)),
XmlReadMode.IgnoreSchema
);
where schemaPath points to an XSD file that was generated earlier in development with a call to
File.WriteAllText(
#"C:\MyTempPath\MyReportName.xsd",
reportData.GetXmlSchema(),
Encoding.Unicode
);
When generating the schema, you will also want that schema to be as complete of a representation of the data as possible, so you will want to use as complete of a hierarchy of data as possible. This is also the XML that the report must be created off of so that its schema matches. If the schema changes, then the report must be opened in the designer with the new data and you must "verify database" and then save the RPT file.

Are you passing along your creditials in your code:
ReportDocument rep = new ReportDocument();
rep.FileName = Server.MapPath("CrystalReport1.rpt");
set.SetDatabaseLogon("username", "password", "sql-server", "database"); // this line pass the login parameters required for login

After long efforts i figured the main reason, there was a mistake in my stored procedure which was returning data.
SP returns data from table1 or table2 (they both have same structure), but when I was picking data from table2 i did not write all the column names which were required.
Seems quite weird , i should get something like column not found error instead of database logon failed.

Try this out. Also make sure you have right version of crystal report in all places
private ConnectionInfo crConnectionInfo = new ConnectionInfo();
ReportDocument rpt = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
CrystalReportViewer1.Width = 900;
CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
BindReport();
}
private void BindReport()
{
rpt.Load(Server.MapPath("ProductList.rpt"));
DataSet ds = getReportData();
rpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rpt;
}
private DataSet getReportData()
{
DataSet ds = new DataSet();
string ConnectionString = ConfigurationManager.ConnectionStrings["myconn"].ConnectionString;
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "GetProductList";
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds, "ctable");
con.Close();
return ds;
}

I was facing the same issue at the time, when I moved the application from the development machine to the real server. It was an IIS7 MVC application( CR 13.0) with trusted authentication to the SQL server.
The way I fixed it, was by creating a new application pool for the application. I give permission for the new application pool user IIS APPPOOL\applicationpoolname to the SQL server database that was used in the application.
Then the error went away.
My assumption is that, the userlogininfo applied through code is not always used by the CR runtime , instead it uses the IIS user login info.

Related

DataSource for DataGridView is not showing the data of the table

Within Visual Studio 2017 I just created a DataGridView and linked a DataSource to it. It asked me for a connection string (which I gave). It showed the table from the database that I wanted in the DataGridView and it created automatically the correct columns within the DataGridView for me.
But for some reason when I start the application it does not show any data. I assume it connects to the database correctly otherwise it couldn't possibly know the name of my table and the columns within it. So how comes it sees my table but does not get the data?
So to test this I tried to make a simple RadDropDownList with help of the guide "LINK" But by following the steps for "Data binding at design time" I get the same exact result. It seems like it connects correctly but then it shows no data.
Does anyone knows why Visual Studio connects to my database with help of a DataSource but then does not gets any data from the table? Am I perhaps missing something?
Added:
I am using Microsoft SQL Server.
Yes, I have checked if the table contains data.
Try this:
string connectionString = "Data Source=.;Initial Catalog=pubs;Integrated Security=True"; // put your connection string
string sql = "SELECT * FROM Authors"; // change your table name
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
dataadapter.Fill(ds, "Authors_table");
connection.Close();
dataGridView1.DataSource = ds; // put your gridview name
dataGridView1.DataMember = "Authors_table";

Crystal Report with sub-report "The report you requested requires further information"

I am building a Crystal Report in Visual Studio 2010 using C#. My report must contain a sub-report. When I run my report individually it works perfectly, but when I add sub-report I immediately get the dialog window saying "The report you requested requires further information" I can only type in name and password, database name field is read only. When I enter the information it loads for a few seconds and then reappears again
My original report and sub-report are using different stored procedures that are put into one DataSet each report is connected to its own stored procedure. When I run only main report it runs fine, but when the sub-report is added the diaglog reappears.
I am connecting page to the report like this, I hard code all the fields for now, and the sub-report is linked to the main report with facility_id
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["chartsdbnewConnectionString"].ConnectionString);
ReportDocument rdoc = new ReportDocument();
cn.Open();
SqlCommand cmd = new SqlCommand("RIV_RPT_CENSUS_ASOFDATE_copy_jenny", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#facility_search_ind", 0);
cmd.Parameters.AddWithValue("#facility_id_from", 50);
cmd.Parameters.AddWithValue("#facility_id_to", 50);
cmd.Parameters.AddWithValue("#facility_name_from", ' ');
cmd.Parameters.AddWithValue("#facility_name_to", "zz");
cmd.Parameters.AddWithValue("#Resident_search_ind", 1);
cmd.Parameters.AddWithValue("#Resident_id_from", 0);
cmd.Parameters.AddWithValue("#Resident_id_to", 0);
cmd.Parameters.AddWithValue("#Resident_name_from", "A");
cmd.Parameters.AddWithValue("#Resident_name_to", "ZZZZ");
cmd.Parameters.AddWithValue("#AsOfDate", "2016-01-27");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable ds = new DataTable();
da.Fill(ds);
rdoc.Load(Server.MapPath("CrystalReport.rpt"));
rdoc.SetDataSource(ds);
Session["ReportDocument"] = rdoc;
crs1.ReportSource = (ReportDocument)Session["ReportDocument"];
crs1.DataBind();
cn.Close();
I spent a lot of time googling this issue but none of the solutions online worked. I feel that I connect my sub-report not in the correct way. I still very new to the Crystal Report technology. Please help, its my 3rd day slaving on it.
You need to give the subreport a datasource in your code behind as well. Something like:
rdoc.OpenSubreport("my_awesome_subreport.rpt").SetDataSource(ds);

Display More Added Columns by the user In Report viewer

I created a windows form application using c# and sql database.
At the run time, I was able to add/delete columns in the datagridveiw and get the data updated. This way, when I reopen the application the data are saved, I was able to get a report viewer that I designed statically with the wizard. However it only shows the columns that were added in the design phase not the run time.
How can I display the modifications that occur to the data (adding or deleting columns) at the run time in the report viewer?
Suppose I designed the report to have three columns Name, LastName, money, and get the report successfully at the runtime, and then I added some new columns say (Age,Country)
during the run time. When I try to get the report I only get 3 columns (Name, LastName, Money) with updated Rows But not added columns.
I just solved the same problem. I was searching for a few days in internet but I couldn't find a good answer for it. So I hope my post will help somebody to overcome the same problem.
All you need to do - just define manually the connection, refill the dataset and bind the source to reportviewer. Here is my project example:
using Microsoft.Reporting.WinForms;
private void ReportForm_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\GD Robotics\VisualProjects\GDPolin\GDPolin\PolinaDB.mdf;Integrated Security=True;Connect Timeout=30";
conn.Open();
SqlDataAdapter reportDBTableAdapter = new SqlDataAdapter("SELECT * FROM [ReportDB]", conn);
DataTable polinaDBDataSet = new DataTable();
reportDBTableAdapter.Fill(polinaDBDataSet);
conn.Close();
this.reportViewer1.Reset();
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.ReportPath = #"D:\GD Robotics\VisualProjects\GDPolin\GDPolin\Report1.rdlc";
ReportDataSource rds = new ReportDataSource("DataSet1", polinaDBDataSet);//"DataSet1" is the name of your dataset. Go to .rdlc form>VIEW>Report Data>"Right click on dataset">Dataset Properties
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.RefreshReport();
}

DataTable is not populated correctly

I have a C# application. Here is a piece of my code:
private const string SqlLatestFiles = "SELECT Name, [FileId],[Filename],Age,[ModifiedDT],RcvDT,[Records],[InvalidRecords],[V2Stage],[V1Stage],[FileType] FROM MyDB.[dbo].[LatestFiles] order by [ModifiedDT] DESC;";
...
using (var da = new SqlDataAdapter(SqlLatestFiles, myConnectionString))
using (var dt = new DataTable())
{
da.Fill(dt);
...
}
When I run the SqlLatestFiles in the SQL Server Management Studio, the selected data is correct. But when the DataTable dt is populated, V1Stage is 0. It didn't happen before this morning, and I doubt I could change anything. Does anybody have any idea why such thing could happen?
Thanks.
I recalled one thing that I changed yesterday: I created a copy of a database that is used in the LatestFiles view among other databases. It is the very database where the V1Stage should come from.
And yes! I removed the copy of the database, and now it works!
I guess the DataAdapter somehow confuses the two databases that yesterday were exact copies of each other.

Dynamically set Crystal Report still asks for db login

I am trying to deploy Crystal Reports in my MVC application. To get full use of the Crystal Report Viewer, I have to use a webform, which is working fairly well in my dev environment.
The application will be deployed on the user's servers and connect to their personal dbs. This means I do not have the final connection information when designing the report or the application.
I am able to successfully connect using their entries in the web.config file, load a DataTable with the report information, and pass it to the report. However, the report is still asking for the db credentials. The report is set to connect to my db, so it asks for my credentials and will not proceed without them. However, the final report shows the correct info from their db.
I am not sure if I need to change something in the report, or in the code behind. This is how I am setting the report ReportSource now:
protected void Page_Load(object sender, EventArgs e)
{
string strReportName = System.Web.HttpContext.Current.Session["ReportName"].ToString();
try
{
ReportDocument rd = new ReportDocument();
string strRptPath = Server.MapPath("~/") + "Rpts//" + strReportName;
rd.Load(strRptPath);
SqlParameter[] sqlParams = {};
DataTable testDt = DBHelper.GetTable("rptInvtDuplDesc", sqlParams);
rd.DataSourceConnections.Clear();
rd.SetDataSource(testDt);
CrystalReportViewer1.ReportSource = rd;
}
else
{
Response.Write("<H2>Nothing Found; No Report name found</H2>");
}
}
How do I prevent the report from asking for the original credentials?
EDIT:
If I pass the login to my db like this:
rd.SetDatabaseLogon("username", "password");
I do not get the db login again. The credentials have to be for the db used to create the report, but the displayed results are from the DataTable populated in the method above. If it has the data it needs from the current db, why does it need to connect to the original db?
EDIT2:
I have 2 data sources for this report. One is a table from the db and the other is the result from a stored procedure. I have now learned that is the cause of the extra login.
Have a look at my Blog post here on this.
There are a couple of actions required, but the main one is to create a new TableLogOnInfo instance, and then apply is using ApplyLogOnInfo.
You have to provide credentials for each datasouce in the report.
Ideally, the report will have a single datasource. If this is not possible, you need to provide credentials for each, or data for each.
Something like this works well if you want to provide the data:
rd.Database.Tables[0].SetDataSource(testDt);
rd.Database.Tables[1].SetDataSource(micssys);
Otherwise, something like this will allow the report to access the db directly for each datasource:
rd.SetDatabaseLogon("username","password}");

Categories