Crystal Report 2011 Login prompt in asp.net - asp.net

We are using Crystal Reports 2011 & SQL Server 2008 (Windows 7 64 bit). Whenever I try to deploy the crystal reports in the IIS it is always prompting enter the database login information. I have tried the below options
Set the login information in the code
Set IIS app pool to LocalService
Nothing works. Here is the code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ConfigureCrystalReports();
}
else
{
ReportDocument doc = Session["Report"] as ReportDocument;
SetLogon(doc);
CrystalReportViewer1.ReportSource = doc;
CrystalReportViewer1.RefreshReport();
}
}
private void ConfigureCrystalReports()
{
ReportDocument reportDoc;
if (!IsPostBack)
{
reportDoc = new ReportDocument();
reportDoc.Load(Server.MapPath("~/Sample.rpt"));
Session.Add("Report", reportDoc);
}
else
{
reportDoc = Session["Report"] as ReportDocument;
}
SetLogon(reportDoc);
CrystalReportViewer1.ReportSource = reportDoc;
CrystalReportViewer1.RefreshReport();
}
private void SetLogon(ReportDocument reportDoc)
{
var connectionInfo1 = new ConnectionInfo()
{
ServerName = #"ODBCDSN",
DatabaseName = "hrdw_old",
IntegratedSecurity = true
};
SetDBLogonForReport(connectionInfo1, reportDoc);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo1, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo1;
tableLogonInfo.ConnectionInfo.Type = ConnectionInfoType.SQL;
table.ApplyLogOnInfo(tableLogonInfo);
}
reportDocument.SetDatabaseLogon(connectionInfo1.UserID, connectionInfo1.Password);
}
}
Steps tried in IIS:
Application pool: ASP.NET 4.0 Default app pool
Also enabled Windows Authentication in IIS & disabled anonymous authentication.
Tried anonymous authentication only.
SQL Server has both windows and sql server authentication.
I will not be able to use dataset since the crystal reports will be developed by someone using command objects. It works perfectly good in the Visual studio 2010 environment. But doesnt work in IIS.
Am I missing something basic? Any help is appreciated.
Thanks
Shankar.

Here is how this was solved. It was a bit of workaround
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc = doc.ReportClientDocument;
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rcd = rptClientDoc;
string server = #"<SERVER>";
string db = "<DATABASE>";
string user = "<USER>";
string pass = "PASSWORD";
rptClientDoc.DatabaseController.LogonEx(server, db, user, pass);
//Create the logon propertybag for the connection we wish to use
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag logonDetails = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
logonDetails.Add("Auto Translate", -1);
logonDetails.Add("Connect Timeout", 15);
logonDetails.Add("Data Source", server);
logonDetails.Add("General Timeout", 0);
logonDetails.Add("Initial Catalog", db);
logonDetails.Add("Integrated Security", "false");
logonDetails.Add("Locale Identifier", 1033);
logonDetails.Add("OLE DB Services", -5);
logonDetails.Add("Provider", "SQLOLEDB");
logonDetails.Add("Use Encryption for Data", 0);
//Create the QE (query engine) propertybag with the provider details and logon property bag.
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag QE_Details = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
QE_Details.Add("Database DLL", "crdb_ado.dll");
QE_Details.Add("QE_DatabaseName", db);
QE_Details.Add("QE_DatabaseType", "OLE DB (ADO)");
QE_Details.Add("QE_LogonProperties", logonDetails);
QE_Details.Add("QE_ServerDescription", server);
QE_Details.Add("QE_SQLDB", "True");
QE_Details.Add("SSO Enabled", "False");
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConnInfo;
CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfos oldConnInfos;
oldConnInfos = rcd.DatabaseController.GetConnectionInfos(null);
for (int I = 0; I < oldConnInfos.Count; I++)
{
oldConnInfo = oldConnInfos[I];
newConnInfo.Attributes = QE_Details;
newConnInfo.Kind = CrystalDecisions.ReportAppServer.DataDefModel.CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
try
{
rcd.DatabaseController.ReplaceConnection(oldConnInfo, newConnInfo, null, CrystalDecisions.ReportAppServer.DataDefModel.CrDBOptionsEnum.crDBOptionDoNotVerifyDB);
}
catch (Exception ex)
{
Label1.Text = ex.Message;
return;
}
}
doc.SetDatabaseLogon(user, pass);
To ensure that there is no login prompt at all at first I had to login to the controller and then set all the login credentials. Ensure that login credentials are reused during post back as well. After this is done, login using the reportdocument as well. This solves the issue of login prompt coming again and again.
Thanks
Shankar

Related

session time out before specefied time in asp.net application

I have a web application hosted on IIS 7 running on windows server 2008 R2.Users of my application where able to login the application with default session timeout of 20 minutes which is configured in web.config file and session settings on IIS 7.
Users authentication is done by active directory domain services running on another server, that i implemented using this code.
code:
public bool CheckUserInActiveDirectory(string userName)
{
try
{
string filter = "(&(objectCategory=person)(objectClass=user)(SAMAccountName=" + userName + "))";
string[] propertiesToLoad = new string[2] { "name", "PwdLastSet" };
DirectoryEntry root = new DirectoryEntry(activeDirectoryAddress);
root.AuthenticationType = AuthenticationTypes.None;
root.Username = activeDirectoryName + activeDirectoryDefaultUser;
root.Password = activeDirectoryDefaultPass;
DirectorySearcher searcher = new DirectorySearcher(root, filter, propertiesToLoad);
int count = searcher.FindAll().Count;
if (count >= 1)
return true;
else
return false;
}
catch (Exception ex)
{
throw;
}
}
since my application server (with windows server 2008 R2) is joined to Domain Group, Users session is null, less than 20 minutes and the session time is not equal for other users, and is changed every time for each user.
Finally the user is redirected to login page.Is there any body who knows the reason and guide me how to resolve the issue.
code :
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserSession"] == null)
Response.Redirect("LoginPage.aspx");
}

Deployment of ASP.NET 4.5 web app w / SQL Server CE 4.0 database to GoDaddy hosting using VS 2013

So far, I have this ASP.NET web form app project, which contains Microsoft SQL Server CE 4.0 (Compact Edition database file) in Visual Studio 2013 community edition. It's configured as follows (showing the most critical points):
bin folder:
bin\System.Data.SqlServerCe.dll
bin\System.Data.SqlServerCe.Entity.dll
bin\amd64
bin\amd64\Sqlceca40.dll
bin\amd64\Sqlcecompact40.dll
bin\amd64\ Sqlceer40EN.dll
bin\amd64\Sqlceme40.dll
bin\amd64\Sqlceqp40.dll
bin\amd64\Sqlcese40.dll
bin\amd64\Microsoft.VC90.CRT
bin\amd64\Microsoft.VC90.CRT\Microsoft.VC90.CRT.manifest
bin\amd64\Microsoft.VC90.CRT\msvcr90.dll
bin\x86\Sqlceca40.dll
bin\x86\Sqlcecompact40.dll
bin\x86\Sqlceer40EN.dll
bin\x86\Sqlceme40.dll
bin\x86\Sqlceqp40.dll
bin\x86\Sqlcese40.dll
bin\x86\Microsoft.VC90.CRT
bin\x86\Microsoft.VC90.CRT\Microsoft.VC90.CRT.manifest
bin\x86\Microsoft.VC90.CRT\msvcr90.dll
web.config contains:
<connectionStrings>
<add name="conn"
connectionString="Persist Security Info = False;File Mode ='Read Write';Encryption Mode=Platform Default;Password='pwd';DataSource=|DataDirectory|\MyDatabase.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
Code-behind contains:
using System.Data.SqlServerCe;
and simple test code snippet listed below:
protected void Page_Load(object sender, EventArgs e)
{
DataTable _dt;
string _testPoint = String.Empty;
try
{
// sample sql statement
string _sql = "SELECT CATEGORY FROM TBL_CATEGORY";
string _connString = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
#region TEST AREA
// test points to trace the error origin
_testPoint = "tp1";
SqlCeConnection _sqlceConn = new SqlCeConnection();
_testPoint = "tp2";
_sqlceConn.ConnectionString = _connString;
_testPoint = "tp3";
_sqlceConn.Open();
_testPoint = "tp4";
#endregion
#region to be used in production
//using (SqlCeConnection _connSqlCe = new SqlCeConnection(_connString))
//{
// using (SqlCeCommand _commandSqlCe = new SqlCeCommand(_sql, _connSqlCe))
// {
// _commandSqlCe.CommandType = CommandType.Text;
// _connSqlCe.Open();
// using (SqlCeDataReader _dataReaderSqlCe = _commandSqlCe.ExecuteReader(CommandBehavior.CloseConnection))
// {
// _dt = new DataTable();
// _dt.Load(_dataReaderSqlCe);
// _dataReaderSqlCe.Close();
// }
// }
// _connSqlCe.Close();
//}
//int _rowCount = _dt.Rows.Count;
#endregion
}
catch (AccessViolationException ax) { Label1.Text += "A: " + ax.Message; }
catch (DataException dx) { Label1.Text += "D: " + dx.Message; }
catch (Exception ex) { Label1.Text += "X: " + ex.Message; if (ex.InnerException != null) { Label1.Text += ex.InnerException.Message; } }
}
Everything seems OK while running in Visual Studio 2013 IDE. But when deployed to GoDaddy hosting account (note: to the best of my knowledge it's environment set to Medium Trust) it fail at the very first test line:
SqlCeConnection _sqlceConn = new SqlCeConnection();
with exception shown below (including inner exception):
The type initializer for 'System.Data.SqlServerCe.SqlCeConnection' threw an exception.
The type initializer for 'System.Data.SqlServerCe.KillBitHelper' threw an exception.
Apparently, the app does not recognize the referenced SQL Server CE library, even though all .dll exists on web server (checked it using GoDaddy file management tools).
QUESTION: how to fix this deployment issue?
SUB-QUESTION: Is it possible to use simple x-copy deployment if SQLite database file is used instead of SQL Server CE in Medium Trust environment?

Send mail from ASP.Net that automatically saves to client's Outlook calendar

I just want to send a reminder mail from my ASP.Net application to Outlook that automatically saves to the targeted Outlook Emailid calandar.
I have implemented this, but this is working on my system's Outlook only. It doesn't work on other systems.
protected void btSent_Click(object sender, EventArgs e) { SendMail("xyz#xyz.com", "xyx"); } public void SendMail(string targetMail, string shownTargetName) { MailAddress fromAddress = new MailAddress("xyz#xyz.com", "MailSendingProgram"); MailAddress toAddress = new MailAddress(targetMail, shownTargetName); String fromPassword = "xyz"; String subject = "Test Recurrence"; String body = #" Here you can put in any text that will appear in the body multilined and even in "; SmtpClient smtp = new SmtpClient { Host = "smtp.xyz.com", Port = 25, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) };
using (MailMessage message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
}
)
{
try
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.Send(message);
lbError.Text = "E-Mail sent!";
Microsoft.Office.Interop.Outlook.Application olApp = new Microsoft.Office.Interop.Outlook.Application();
CreateNewRecurringAppointment(olApp);
Marshal.ReleaseComObject(olApp);
}
catch
{
lbError.Text = "Sending failed, check your internet connection!";
}
}
}
public void CreateNewRecurringAppointment(Microsoft.Office.Interop.Outlook._Application OutlookApp) { Microsoft.Office.Interop.Outlook.AppointmentItem appItem = null; Microsoft.Office.Interop.Outlook.RecurrencePattern pattern = null; try { appItem = OutlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem) as Microsoft.Office.Interop.Outlook.AppointmentItem; // create a recurrence pattern = appItem.GetRecurrencePattern(); pattern.RecurrenceType = Microsoft.Office.Interop.Outlook.OlRecurrenceType.olRecursWeekly; pattern.StartTime = DateTime.Parse("8:35:00 AM"); pattern.EndTime = DateTime.Parse("9:35:00 PM"); // we can specify the duration instead of using the EndTime property pattern.Duration = 60; pattern.PatternStartDate = DateTime.Parse("03/9/2015"); pattern.PatternEndDate = DateTime.Parse("03/9/2015"); appItem.Subject = "Meeting with the Boss"; appItem.Body = "Test Appointment body"; appItem.Location = "P1"; appItem.ReminderSet = true; appItem.ReminderMinutesBeforeStart = 15; appItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; appItem.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy; appItem.Save(); appItem.Send();
//appItem.Display(true);
}
catch (Exception ex)
{
lbRecur.Text = ex.Message;
}
finally
{
if (pattern != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pattern);
}
if (appItem != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(appItem);
}
}
}
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. You can read more about that in the Considerations for server-side Automation of Office article.
Consider using EWS (Exchange Web Services) or standard classes from BCLs (Base Class Libraries). You may find the EWS Managed API, EWS, and web services in Exchange article helpful.

how to link to ssrs report from asp.net webpage

I'm having trouble linking to an ssrs report from my asp.net webpage.
the direct link is
server/Reports/Pages/Report.aspx?ItemPath=%2fRig+Dashboard%2fRig+Status+Report
I also need to pass in two parameters which is FileTypeID and Date
Please help...
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://server/Reports"); // Report Server URL
ReportViewer1.ServerReport.ReportPath = "/Rig Dashboard/Rig Status Report"; // Report Name
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPrintButton = true;
ReportViewer1.ServerReport.Refresh();
The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.
The request failed with HTTP status 404: Not Found.
Your doing it wrong. You are trying to call the 'landing page' : /Reports NOT THE SERVICE: /ReportServer. Yuriy gave you a good place to get started. I can give you an example of how I do it in some local code I use in WPF calling a Windows Form(blech!):
private void ResetReportViewer(ProcessingMode mode)
{
this.reportViewer.Clear();
this.reportViewer.LocalReport.DataSources.Clear();
this.reportViewer.ProcessingMode = mode;
}
private void ReportViewerRemote_Load(object sender, EventArgs e)
{
ResetReportViewer(ProcessingMode.Remote);
reportViewer.ServerReport.ReportServerUrl = new Uri(#"http://server/ReportServer");
reportViewer.ServerReport.ReportPath = "/Folder/ReportName";
reportViewer.RefreshReport();
}
private void ReportViewerRemoteWithCred_Load(object sender, EventArgs e)
{
ResetReportViewer(ProcessingMode.Remote);
reportViewer.ServerReport.ReportServerUrl = new Uri(#"http://server/ReportServer");
reportViewer.ServerReport.ReportPath = "/Folder/ReportName";
DataSourceCredentials dsCrendtials = new DataSourceCredentials();
dsCrendtials.Name = "DataSource1";
dsCrendtials.UserId = "DedicatedUser";
dsCrendtials.Password = "P#ssword(jk)";
reportViewer.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { dsCrendtials });
reportViewer.RefreshReport();
}

Accessing SSRS server report from local application

I have deployed my SSRS reports in the server. Is it possible for me to access that report from my local web application. I have given the server's credentials in the web.config. But still its not displaying the report and it shows some error like Cannot create a connection to data source 'DataSource1'. (rsErrorOpeningConnection).
When I hosted the same application in the server it is working absolutely fine.
Can anyone tell me why am not able to access the reports from my local system?
This is not my code, but ideally is all you have to do. I remember using it successfully in one of previous projects some time back
private void ShowReport()
{
try
{
string urlReportServer = "http://sqlDBServer//Reportserver";
rptViewer.ProcessingMode = ProcessingMode.Remote; // ProcessingMode will be Either Remote or Local
rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer); //Set the ReportServer Url
rptViewer.ServerReport.ReportPath = "/ReportName"; //Passing the Report Path
//Creating an ArrayList for combine the Parameters which will be passed into SSRS Report
ArrayList reportParam = new ArrayList();
reportParam = ReportDefaultPatam();
ReportParameter[] param = new ReportParameter[reportParam.Count];
for (int k = 0; k < reportParam.Count; k++)
{
param[k] = (ReportParameter)reportParam[k];
}
// pass crendentitilas
//rptViewer.ServerReport.ReportServerCredentials =
// new ReportServerCredentials("uName", "PassWORD", "doMain");
//pass parmeters to report
rptViewer.ServerReport.SetParameters(param); //Set Report Parameters
rptViewer.ServerReport.Refresh();
}
catch (Exception ex)
{
throw ex;
}
}
Ref: http://www.codeproject.com/Articles/675762/Call-SSRS-Reports-by-using-Csharp

Resources