Wednesday, August 19, 2009

SQL Server Reporting Service (SSRS) – 401 Unauthorized Access Issue in Production Environment

Let me share with you my experience on one of the issue i had with sql server reporting services in production environment.

Problem Description:
I am using sql server 2008 reporting services for reports in a .Net 3.5 application.

Production Environment:
Application Server: IM-APP1 (this is IIS machine and application is deployed here) has following windows server 2003, .Net 3.5, IIS 6.0
Database and Reporting Server: IM-SQL1 (This server has the database and sql reporting services), windows server 2003, .Net 3.5, SQL Server 2008, SQL 2008 Reporting Services

When i am browsing the application from desktop client, application works fine it fetches the data from database server, but when i navigate to a page, enter the report criteria and hit the button Generate Report then application throws 401-unauthorized access exception.

Now when i host database, reporting services and application on the same server (IM-APP1) then everything works fine.

below is the stack trace of the exception:

Exception Message : The request failed with HTTP status 401: Unauthorized.
Stack Trace : at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods()
at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(String methodname)
at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.SetConnectionSSLForMethod(String methodname)
at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.LoadReport(String Report, String HistoryID)
at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo()
at Microsoft.Reporting.WebForms.ServerReport.SetParameters(IEnumerable`1 parameters)
at Pages_Reports_LogFormReports.DisplayReport(ReportViewer reportViewer, String reportName, ReportParameter[] parmList)

DisplayReport() is the method name which is responsible for generating the report and display it in report viewer object

I reviewed the DisplayReport() method and found that report server user credentials are not passed to the report server, so here what Application server does is when it calls the reports and if the report is hosted on the same server it doesn't need any credential for generating report so the report is working fine, now in other scenario where reports are hosted on different server then Application Server should pass report server user credential to generate the report.

Now the question is how to pass report server user credential from the application.

Here is the solution:

First We need to Create one sealed class to perform this action. This class need to be inherited from IReportServerCredential interface.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Reporting.WebForms;
using Microsoft.ReportingServices;
using System.Security.Principal;
using RA.FRIMS.Settings;

/*****************************************************************************
* Created By : Nizam
* Created Date : Aug 17, 2009
* Description: This is sealed and serializable class and implementing IReportServerCredentials interface.
* This class Provides Network credentials to be used to connect to the report server.
* *****************************************************************************/

[Serializable]
public sealed class ReportServerNetworkCredentials : IReportServerCredentials
{
#region IReportServerCredentials Members
public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName,
out string password, out string authority)
{
authCookie = null;
userName = null;
password = null;
authority = null;

return false;
}

// Specifies the user to impersonate when connecting to a report server.
//A WindowsIdentity object representing the user to impersonate.
public WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}

// Returns network credentials to be used for authentication with the report server.
//A NetworkCredentials object.
public System.Net.ICredentials NetworkCredentials
{
get
{
//you can place below settings in configuration xml file
string userName = "ReportServerUserName";
string domainName = "ReportServerUserInDomainName";
string password = "ReportServerUserPassword";

return new System.Net.NetworkCredential(userName, password, domainName);
}
}

#endregion

}


Now all what you have to do in your display report method is:

//This method display reports in the report viewer object
private void DisplayReport(ReportViewer reportViewer, string reportName, ReportParameter[] parmList)
{
try
{
//For Reports with some input parameters.
reportViewer.ShowCredentialPrompts = false;
reportViewer.ShowParameterPrompts = false;
reportViewer.ShowDocumentMapButton = false;
reportViewer.ShowPageNavigationControls = true;
reportViewer.ShowFindControls = false;
reportViewer.ShowPrintButton = true;

reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;

// Here we are going to pass the ReportServerCredentials to the Report Viewer.
reportViewer.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();


reportViewer.ServerReport.ReportServerUrl = "http:port//ReportServerMachineName
/reportserver";
reportViewer.ServerReport.ReportPath = "ReportFolderName" + reportName;

reportViewer.ServerReport.SetParameters(parmList);
reportViewer.ServerReport.Refresh();

}
catch (Exception ex)
{
//handle exception
}
}

That's all you are done!!! Now run the report.

Please feel free to comment on this post. Critics are highly appreciated. :-)

Wednesday, July 22, 2009

401 Unauthorized access error when accessing web service (Which uses SharePoint-80 application pool and domain user identity) from client machine

PROBLEM Description:

1. I have deployed web service, on the production server, web service that utilizes the MOSS objects / namespaces. In order that the service should be able to access the information i have deployed the service in the same application pool as SharePoint - 80 and provided the website folder with same permissions as the SharePoint site. The end result is that the information is accessible through the service on the local machine.

When the same methods are invoked from any other machine on the network we get the unauthorized 401 error.

If I change the application pool to the default application pool then the methods are accessible but not the information from MOSS as it is not within the same application pool.

The differences between the two application pools are the identities that are used for the services. Default utilizes the network service account while MOSS uses a custom service account.

We need to identify the error for the first scenario and be able to deploy without error the web service in the SharePoint application pool.

Environment:

Product: Visual Studio 2008, MOSS 2007

OS: Windows Server 2003

RESOLUTION:

I am providing you here the troubleshooting steps which I performed to resolve the issue.

[INFORMATIVE AND IMPORTANT]

  • We are having a web service which is consuming services from SharePoint also and running with application pool of SharePoint and identity of the domain user.
  • Everything works fine on the server.
  • But from client machine when we are trying to access the service, it is throwing 401 unauthorized errors.
  • We have set the identity of domain user (say ‘devportal’ user).
  • Now to get the actual issue, we enabled the auditing on the application server.
  • We enabled “Audit account logon events” and “Audit logon events” for failure.
  • Then ran the application again from client machine.
  • After that we saw failure audit in security event log and with event ID of 529,533.
  • This gave me an idea that this is a failure due to Kerberos.
  • So I started troubleshooting from that perspective.
  • I created a sample website (just an html page) and ran it same application pool and identity.
  • Here also I am able to reproduce the issue.
  • Then I made two changes on Active Directory machine:

a. For the server, set the Trust this computer for delegation to any service (Kerberos only).”

b. For the user, set the “All computers”

  • I also set the NTLM authentication on IIS with the following command:

cscript adsutil.vbs set w3svc/NTAuthenticationProviders "NTLM"

  • After that everything worked fine.
  • But it was popping up the dialog box for authentication.
  • I ran the command:

cscript adsutil.vbs set w3svc/NTAuthenticationProviders "Negotiate,NTLM"

Also I configured the SPN with the following commands:

Setspn –A HTTP/NETBIOS_NAME_OF_IIS_SERVER domain\username

Setspn –A HTTP/FQDN_OF_IIS_SERVER domain\username

Now when I browse the web service from client machine then it works fine, problem is resolved -J

But problem still persist on the application server which deployed an application in IIS and that application is consuming this web service

Problem description:

Till now when I browse the web service from server machine or client machine then it works fine

1. I have an application [say DocSytems] deployed on another server [say APPSERVER]

2. DocSytems consumes the web service which is deployed on share point server

3. Now if I access the web service from DocSytems from APPSERVER server machine then it works fine

4. If I call the web service from DocSytems from other machine in the network and login with a domain user name then it doesn’t work

5. But interestingly if I impersonate the domain user (devportal) name which is set in the Identity of the SharePoint-80 app pool and DocSytems application then it works fine

Solution:

• I found that application server’s IIS was not set to Kerberos, i.e. with “Negotiate, NTLM”

• I set the IIS for “Negotiate, NTLM”

To set:

cscript adsutil.vbs set w3svc/WebSite/root/NTAuthenticationProviders "Negotiate,NTLM" ( In yellow color, you need the change it with site Id, in our case it was ‘1’).

To get:

cscript adsutil.vbs get w3svc/WebSite/root/NTAuthenticationProviders

• Then I also found that IE browser (of client) was not able to recognize the windows integrated authentication setting.

• In Internet explorer, I enabled the settings from Toolsà Internet Options à Advanced à Security à “Enabled Integrated Windows Authentication”

• Once I enabled the setting on client machine, everything works as expected.

So the problem is resolved

References on the issue which we resolved:

http://technet.microsoft.com/en-us/library/cc739740(WS.10).aspx

http://support.microsoft.com/kb/832769

http://support.microsoft.com/kb/215383

http://support.microsoft.com/kb/929650

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d3df4bc9-0954-459a-b5e6-7a8bc462960c.mspx?mfr=true

http://support.microsoft.com/kb/909887

http://technet.microsoft.com/hi-in/library/bb742516(en-us).aspx

Additional references:

For your future reference, I am mentioning here few articles related to IIS. Please note that these articles may or may not be related to the current case, but good pointers for keeping them in record book and future study.

1. This article talks about "How to configure applications in IIS 6.0" - http://support.microsoft.com/default.aspx?id=814867


2. This article talks about "How to configure security by using IIS 6.0" - http://support.microsoft.com/default.aspx?id=814874


3. This article talks about "How to performance-tune your applications in IIS 6.0" - http://support.microsoft.com/default.aspx?id=814876


4. This link talks about troubleshooting IIS - http://technet2.microsoft.com/windowsserver/en/technologies/featured/iis/default.mspx

5. IIS Authentication - http://msdn.microsoft.com/en-us/library/aa292114.aspx

Wednesday, June 3, 2009

Recommended 10 Skills for a good developer

DO U DARE TO BE A DEVELOPER ??????????.............THINK TWICE........DO U KNOW LIFE OF A DEVELOPER????.........Ohh U Dare...I think you don't know life of a developer..............OK.........If you really decided to be a developer WHY NOT be a good Developer with good skill set and.........

Here is the Kick........

Web development?
Pretty sure that's been established as important for the last 7+ years now. Today if you look at the market, there are so many technologies going on and you will find most of them are in demand.

SAP, Oracle, CRM, Share point, BizTalk Server…etc
On the other hand you have JAVA, PHP, .Net…..etc

Here I will talk about the core technology and supporting technologies.

1: One of “Big Three” (.NET, Java, PHP)

Choose any one of THREE, all are HOT/DEMANDING/BOOMING
Are you looking for plate form independent life, open source, then go for JAVA or PHP.
Radical shift in the development world (akin to an asteroid hitting Redmond), most developers will need to know at least one of the Big Three development systems — .NET (VB.NET or C#), Java, or PHP — for the near future. It’s not enough to know the core languages, either. As projects encompass more and more disparate functionality, you’ll need to know the associated frameworks and libraries more deeply.

2: Rich Internet Applications (RIAs) – THE WEB 2.0

Today you can count how many people don’t use internet but how many use you cannot. Today everyone wants things to be more personalized, users don’t have time to stay on your page, so how your application will interact with user, how you will represent yourself to the user, so that user can stay and spend a minute on your page. The Internet giants are more focusing on usability, Usability..Usability..Usability.

A lot of applications are there on the internet, and they have implemented mind blowing ideas, only few of them are getting the huge traffic and rest are just running apps, the reason is usability.

The solution is RIAs. Love it or hate it, in the last few years, Flash is suddenly being used for more than just animations of politicians singing goofy songs. Flash has also sprouted additional functionality in the form or Flex and AIR. Flash’s competitors, such as JavaFx and Silverlight, are also upping the ante on features and performance. To make things even more complicated, HTML 5 is incorporating all sorts of RIA functionality, including database connectivity, and putting the formal W3C stamp on AJAX. In the near future, being an RIA pro will be a key resume differentiators.

3: Web development

[JavaScript, JQuery, CSS, HTML, XML, XSLT]

Web development is not going away anytime soon. Many developers have been content to lay back and ignore the Web or to just stick to “the basics” their framework provides them with. But companies have been demanding more and more who really know how to work with the underlying technology at a “hand code” level. So bone up on JavaScript, CSS, and HTML to succeed over the next five years.

4: Web services

[Remoting >> RPC >> Web Services >> SOA]
REST or SOAP? JSON or XML? While the choices and the answers depend on the project, it’s getting increasingly difficult to be a developer (even one not writing Web applications) without consuming or creating a Web service. Even areas that used to be ODBC, COM, or RPC domains are now being transitioned to Web services of some variety. Developers who can’t work with Web services will find themselves relegated to legacy and maintenance roles.

5: Soft skills

Always hard for developers -:)
One trend that has been going for quite some time is the increasing visibility of IT within and outside the enterprise.

Developers are being brought into more and more non-development meetings and processes to provide feedback. For example, the CFO can’t change the accounting rules without working with IT to update the systems. And an operations manager can’t change a call center process without IT updating the CRM workflow. Likewise, customers often need to work directly with the development teams to make sure that their needs are met. Will every developer need to go to Toastmasters or study How to Win Friends and Influence People? No. But the developers who do will be much more valuable to their employers — and highly sought after in the job market.

6: One dynamic and/or functional programming language


Languages like Ruby, Python, F#, and Groovy still aren’t quite mainstream – but the ideas in them are. For example, the LINQ system in Microsoft’s .NET is a direct descendent of functional programming techniques. Both Ruby and Python are becoming hot in some sectors, thanks to the Rails framework and Silverlight, respectively. Learning one of these languages won’t just improve your resume, though; it will expand your horizons.

"Every top-flight developer I’ve met recommends learning at least one dynamic or functional programming language to learn new ways of thinking, and from personal experience, I can tell you that it works."

7: Agile methodologies

[Ideas changes, requirement changes, customer wants a real view on his/her idea, less time to market, so SDL changed and came the Agile Methodologies]

When Agile first time I heard this word, I was a skeptic, along with many other folks I know. It seemed to be some sort of knee-jerk reaction to tradition, throwing away the controls and standards in favor of anarchy. But as time went on, the ideas behind Agile became both better defined and better expressed. Many shops are either adopting Agile or running proof-of-concept experiments with Agile. While Agile is not the ultimate panacea for project failure, it does indeed have a place on many projects. Agile benefits both Vendors as well as customers, it involve customers in every stage of development.
Developers with a proven track record of understanding and succeeding in Agile environments will be in increasingly high demand over the next few years.

8: Domain knowledge


Hand-in-hand with Agile methodologies, development teams are increasingly being viewed as partners in the definition of projects. This means that developers who understand the problem domain are able to contribute to the project in a highly visible, valuable way. With Agile, a developer who can say, “From here, we can also add this functionality fairly easily, and it will get us a lot of value,” or “Gee, that requirement really doesn’t match the usage patterns our logs show” will excel.
As much as many developers resist the idea of having to know anything about the problem domain at all, it is undeniable that increasing numbers of organizations prefer (if not require) developers to at least understand the basics.

Domain knowledge allows you to add value by guiding the client and by proactively anticipating business.

9: Development “hygiene”

I remember the days when I started my career in Software Development; it was very hard for me to get my code sync with the other team member’s code. I was not aware of using any source repository, One day I developed some code and forgot to take backup, I thought coding is completed and then thought to optimize the code, I started with code optimization, finally I realized that my code is totally changed and it becomes buggy, then I thought to revert back to previous code but by that time I forgot what code I had written previously -:), at the end there was no option for me and again started coding from scratch, this is one scenario you can understand the importance of development hygiene.

A few years ago, many (if not most) shops did not have access to bug tracking systems, version control, and other such tools; it was just the developers and their IDE of choice. But thanks to the development of new, integrated stacks, like the Microsoft Visual Studio Team System, and the explosion in availability of high quality, open source environments, organizations without these tools are becoming much less common. Developers must know more than just how to check code in and out of source control or how to use the VM system to build test environments. They need to have a rigorous habit of hygiene in place to make sure that they are properly coordinating with their teams. “Code cowboys” who store everything on a personal USB drive, don’t document which changes correspond to which task item, and so on, are unwelcome in more traditional shops and even more unwelcome in Agile environments, which rely on a tight coordination between team members to operate.

10: Mobile development

The late 1990s saw Web development rise to mainstream acceptance and then begin to marginalize traditional desktop applications in many areas. In 2008, mobile development left the launch pad, and over the next five years, it will become increasingly important. There are, of course, different approaches to mobile development: Web applications designed to work on mobile devices, RIAs aimed at that market, and applications that run directly on the devices. Regardless of which of these paths you choose, adding mobile development to your skill set will ensure that you are in demand for the future.

!!!!!!!! Hey if you have all above skills , you are a good developer then....you can share your experience here by putting few lines of comments !!!!!!!!!!!

Get the key facts on a wide range of technologies, techniques, strategies, and skills with the help of the concise need-to-know, Please click here and keep abreast with upcoming technologies.

HAPPY CODING!!!!!!!!!!!!!!!!!!!!!

Sunday, April 5, 2009

Quick and Simple Debugging Techniques

Hello Developer’s, howz your coding life going on?? here is a short article for you, I know that it will be very frustrating to read this full article but Dude keep patience and read it, this article will really help you.


Do you remember the last time when you fixed a small but trivial bug in your system, if you did then just try to remember how did you found the cause of the bugs ?????, which category the cause belongs to ??? (was it a functional error, typo error, coding error, null reference error or caching error), now how did you fixed the bug what steps you took to fix the bugs?????????.


Truly speaking my experience, sometimes I got a bug in the system and searching the cause of the bug took more time than fixing the bug, because bug was simple typo/coding/null reference error. So guys be careful, these typo/syntactical/null reference errors….etc. category of bugs becomes more trivial and it takes a lot of time of developer. So now we should have some salutary lessons from our last small trivial bug, so that in future these issue will never come.


Congratulations!!!! You are one of the few who realize that over 80% of errors are simple and easy to fix. It is important to realize this as it can save a lot of time. Time that could be wasted making unnecessary changes, that in turn can cause further problems.

Programming is a humbling experience. An experience that causes one to reflect on human error. One major cause of these errors is syntax, syntax, syntax. We tend not to notice when we have made a typo. It is too easy to spend an hour trying to fix a problem that was caused by a typo. Accepting human error, that you made a mistake, is a reasonable first assumption.

Another important assumption to fixing problems is Occam's razor - the simplest explanation is more often than not the best. When we initially expect a simple error we don't try to over complicate things and we are more likely to use basic techniques to trap the error; we use simple debugging procedures.

Sometimes just writing a message is enough to see what is going on. One easy technique is to trap the error in a try catch block and write the error message. Its surprising how often this simple technique is not used.

In asp.net there is a custom errors mode remote only. What this does is display the exception only on the local server, but anywhere else. Other users of your application may be directed to a customized error page, while you figure out what's going on.

A very important step to avoiding errors in your application is testing. This is best done on a separate machine to the development and production servers. Even if you don't have access to a test environment this is no reason not to test. We developers are not the best testers -:) . Get someone else or preferably a group to test, believe me you'll save time and probably money.

One of the most common errors is the 'object reference not set to an instance of an object'. Null reference errors are common too. Something, a reference or a parameter for example, is missing. So check the page references and parameters. Look in that error line to see what may be missing or null. Write any values that may be null.

A simple thing that you can do is continue to practice. Programming in an unfamiliar language is slow to start with, but experience is cumulative. As you get more practice, things like error handling become easier. It doesn't become easier if you just copy & paste all the time, there is no substitute for understanding what's going on.

There are many debugging techniques, but that is not the point of this article. Its not until I started to appreciate the number of my errors and the simplicity of fixing them, that I really started to make progress. At times I am still guilty of skipping the diagnosis and heading straight for the medicine cupboard. This has almost always been a mistake.

I hope that you avoid some of the frustrations that I have had over the years by not ignoring human error and accepting how simple steps can resolve most problems.

Happy Coding! Enjoy Coding!!!!!!!!!