Reports Timeout when Opening From ASP.Net ReportViewer - sharepoint-2010

I use this c# code for opening reports from SharePoint 2010 site and SQL Server Reporting Services 2012.
if (!IsPostBack)
{
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("https://site.com/_vti_bin/reportserver");
ReportViewer1.ServerReport.ReportPath = "https://site.com/sites/ssrs/Reports/Report1.rdl";
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowCredentialPrompts = false;
IReportServerCredentials irsc = new ReportViewerCredentials("user", "pass", "domain");
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.Refresh();
}
I can open the reports from SharePoint site, but when I try to open them using the above code in ASP.Net page they timeout. The code works fine since I have succeed to open reports from my test farm. In my production farm, I get the message:
"The underlying connection was closed: The connection was closed unexpectedly."
The interesting thing is the reports opened twice (in two days) and when I tried to open other reports, it just failed like before. This happened when I restated IIS, but it doesn't happen again.
I have all the permissions on the server and SharePoint Farm. The report is just a page with a line on it, it doesn't even have a data source.

Related

hosting ASP.NET Core web app on windows server

I have a ASP.NET web application, written by the use of Razor pages and .Net 6. When I was working on my own pc, every thing was OK. Now, I should take the web application to the server computer in a way that many users can use the application.
I published the application into a folder and take that to the server computer.
On the server computer, I use IIS and add a new website which refers to the published folder of application as physical path.
on a client computer, when I go to the website address of the application, the html page and css styles all are OK, but I got the error:
Login failed for user 'ERTEBATCITFOOD$'.
I also provide a piece of my asp.net code for more information. For example, this is what I wrote for connecting to database and making a query:
string connectionString = "Data Source=citfood;Initial Catalog=food;Integrated Security=True";
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string sql1 = "SELECT date, foodName, price FROM [View_1] WHERE userId = #userId " +
"AND date = #thisDate";
using (SqlCommand command = new SqlCommand(sql1, connection))
{
//do something
}
}
}
I don't know what is wrong here...

Not able to access SPSite object, throwing exception

try
{
string targetSite = "https://abc.xyz.com/";
using (SPSite scSite = new SPSite(targetSite))
{
lblStatus.Text = "SharePoint Connection - Success";
}
}
catch (Exception ex)
{
lblStatus.Text = "SharePoint Connection - Success";
}
Trying to run above code in visual studio 2012 in console application then it is running fine but if I try to run same in web application project then it is throwing below exception. I am trying this code on server where SharePoint 2010 is installed and using .NET 3.5 Any clue why this is happening!!
System.IO.FileNotFoundException: "The Web application at http://abc.xyz.com could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
Here are the most common reasons this error can occur:
The code is executed on a different machine - The SharePoint object model (except the Client API) requires to be run on the SharePoint server itself. It is not possible to run the application on a server which is not within the same SharePoint farm the code is trying to access.
Insufficient Rights on the site collection - The code is executed in context of an account which does not have read permission on the site collection
Incorrect Url being used - Verify that the site works correct in a browser and double check that the server is correct registered in the AAM settings
Incorrect bitness - The SharePoint object model needs to be executed with the same bitness as the operating system. That means you cannot use the SharePoint object model in a 32-bit application if the Operating System and SharePoint are installed as 64-bit version. Ensure to compile the project using the correct bitness (64-bit on a 64-bit machine vs. 32-bit on a 32-bit machine)
Incorrect .NET framework version - Ensure that the project is configured to use .NET 3.5 for SharePoint 2010 and below and .NET 4.0 for SharePoint 2013
Source
Also Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable.

Create data source in Report Builder 3.0 to a data cube using "current windows user" credentials

I have Report Builder 3.0 installed on my local PC. I am creating a new report and adding an embedded data source to a SQL Server Analysis Services database.
When I build the connection string of the data source, choosing the server name and the database name, I click 'Test Connection' and receive a message saying "Test connection succeeded". So far, so good.
I close the connection properties with the OK button, and on the Data Source Properties window I click the 'Test Connection' button. This time I get an error saying "The connection either timed out or was lost".
If I ignore the error then I can successfully add a dataset to my report and add data from the dataset in to the report design, but when I try to run the report (on my local PC) I again get an error connecting to the data source.
My best guess is that the connection that succeeded is running under my credentials, whereas the connection that fails is running as some other credential and so needs to use Kerberos delegation to pass my credentials along, but that is only a guess and even if I am correct I am at a loss to understand how to fix the issue - I don't know what other credentials may be being used and I have already set SPN's for the Analysis Services service account.
So it turns out that it was a Kerberos issue as I suspected, and I was also correct that Report Builder was testing the connection using some process running under another authentication context.
It turns out that when setting up Report Builder (and I had forgotten it) that you specify a default SSRS Report Server (see screenshot). It must be that when testing data sources or running reports that it connects to that default Report Server and does the work from there - I was assuming that everything was running locally!
Once I figured that out it was just a case of finding a good guide on how to configure SSRS for Kerberos and everything started working. In my case the only bit that I hadn't already done was to add the <RSWindowsNegotiate/> setting to the AuthenticationTypes in the rsreportserver.config file

Event viewer log creation error with MVC 4

Action Method
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
LogError("lok", "lok2", "lok3");
return View();
}
LogError Method
private void LogError(string transactionId, string sAmountPaid, string deviceId)
{
// Creating the source, which will generate error
if (!EventLog.SourceExists("MyApplication"))
{
//Creating log, where error will be logged
EventLog.CreateEventSource("MyApplication", "MyLog");
}
// Creating object of EventLog to log error
var myAppLog = new EventLog { Source = "MyApplication" };
//Writing error to log
myAppLog.WriteEntry(transactionId + sAmountPaid + deviceId);
}
When I run Home page it always shows "Error. An error occurred while processing your request.".I suspect this is due to unable to create log on "Event Viewer".When I run above code on local host it's working fine.But when I publish it into IIS server on Windows Server 2012 it's giving above error.
My Question: Should I enable any kind of permission for create log on Event viewer.If so how to do that ? My IIS is working on Windows Server 2012.
This has been asked before. The following link is to that discussion.
Writing to an event log in ASP.NET on Windows Server 2008 IIS7
You will need to give the application the privileges to write to the Windows Event Log.
However, it is not recommended because of several reasons.
Does not scale.
Introduces an attack vector to the server itself, that can be exploited if your application is not secured properly.
Application cannot be hosted in a 'shared hosting' host solution and you would have to have access to OS itself to grant these (or a system that allows this like cPanel)
Alternatives to logging into windows event log:
Log into a Database or to Files
In a distributed architecture, or enterprise level system, send the event log entries into a queue system that passes the data to an aggregation system.
You need admin privilege to create an event source, becuase the name has to be unique, and to check whether it is all the registry items need to be checked including security. I doubt you want to giv your IIS account local admin though.
Way we do this is (for desktop apps), is our installer creates the event source (as admin), and then our apps just read write from it.

MVC 4 - how to change default SQL Server Express database location

In VS 2012 I created a new MVC 4 project starting from the internet application template, then changed its properties to use SQL Server Express instead of LocalDB, then tried successfully to register a new user.
First, the project created its own membership database in the App_data folder, but for deployment reasons I wanted to change the database location, so I moved the database physical files from C:\MyProject\App_Data\ to C:\MyData and modified the related path in the web.config file. To ensure that the database is reachable by the SQL Server Express instance, I added my own user account with full access in the properties security tab, then successfully shown its data in SQL Server Management Studio.
Now, when I run the project, and click on the "log in" link, the debugger stops at LazyInitializer.EnsureInitialized and fails with an error; the inner exception of the error message says:
Database
'C:\MyProject\App_Data\aspnet-MyProject-20121206123456.mdf' already
exists. Choose a different database name.
Cannot attach the file 'C:\MyData\aspnet-MyProject-20121206123456.mdf' as database
'aspnet-MyProject-20121206123456.mdf'
I checked all the project to find any different database connection settings but found nothing.
Within VS, when I use the server explorer to view the database tables data, I cannot find "show data" option when I right click on one of the displayed tables, when I go to C:\MyData\ folder to see the physical database files properties, in the security tab, I find that each time I run the project my account using full access was removed.
Also the browser is displaying the next Exception text:
The data provider. Net Framework requested was not found. It may not be installed.
C:\MyProject\Filters\InitializeSimpleMembershipAttribute.cs Ligne : 42
Ligne 40 : }
Ligne 41 :
Ligne 42 : WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
Ligne 43 : }
Ligne 44 : catch (Exception ex)
It looks like a Visual Studio 2012 bug which doesn't recognize SQL Server 2012 Express instance. I have downloaded Microsoft WebMatrix2 and used it to load the website and could successfully log in using the moved membership database.
With this bug I've lost 2 days trying to find a solution.