Tuesday, 16 February 2016

Error occurred in deployment step 'Recycle IIS Application Pool'


So you have built a solution in Visual Studio and you use the Deploy option on the Build menu to deploy the solution to your local SharePoint instance for testing. Your solution builds okay, but when you get to the actual deployment step it's just not happening. You might also see "<nativehr>0x80070005</nativehr><nativestack></nativestack>Access denied", or a suggestion to check that you have set the Url correctly and the site collection exists. You're sure you set the Site URL correctly in the project properties. What's going wrong?

What makes this error so confusing is that it talks about recycling IIS, and yet we know we can do an IIS recycle or an IISRESET.
 
The problem here is that the account you are using to run Visual Studio does not have sufficient permissions on the SharePoint site. Several people have suggested fixing this by granting Shell Admin to the account in PowerShell or going into SQL Server and modifying permissions. I have found that by far the easiest fix for this is to go into Central Administration and add the user account that runs Visual Studio (presumably your logged in account) to the site collection administrators by going to Central Administration -> Application Management -> Change site collection administrators. You can also do this through site collection administration (site collection administrators in the ribbon on the Permissions page).

You could try just adding the account as a site owner but you might encounter problems activating features and so on - easier just to add to site collection administrators and be done with it. Obviously this doesn't apply to your test and production environments.

Thursday, 5 November 2015

Unable to find Custom fields in Taleo Connect Client (TCC) Export



In TCC, user-defined fields (UDF) are not included in the product integration packs (PIP). If a zone's UDF can't be found in TCC, synchronize the PIP with the zone.


Prerequisite:
TCC > Product Integration Pack
Steps:
  1. Click Synchronizing User-Defined Fields.
  2. If necessary, click Yes to close all editors.
  3. Select Product.
  4. Select Endpoint.
  5. Click Synchronize.

Locations of the Product Integration Pack tab and Synchronize button.

Related concepts
Document 1045262.1 RP6405 - Relation Not Found for the Entity in the Feature Pack
Document 1047969.1 SD6427 - User-Defined Field Names in TCC
Related tasks
Document 1047581.1 SD6010 - Upgrading Taleo Connect Client

Wednesday, 9 September 2015

IIS7 Integrated mode: Request is not available in this context exception in Application_Start

The “Request is not available in this context” exception is one of the more common errors you may receive on when moving ASP.NET applications to Integrated mode on IIS 7.0.  This exception happens in your implementation of the Application_Start method in the global.asax file if you attempt to access the HttpContext of the request that started the application. 

Update: We recently launched a service that significantly helps you understand, troubleshoot, and improve IIS and ASP.NET web applications. If you regularly troubleshoot IIS errors, manage Windows Servers, or tune ASP.NET performance

The error looks something like this:

Server Error in ‘/’ Application.


Request is not available in this context

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request is not available in this context
Source Error:
Line 3:  {
Line 4:      HttpContext context = HttpContext.Current;
Line 5:      String appPath = context.Request.ApplicationPath;
Line 6:  }
Line 7:  </script>

Source File: c:inetpubwwwrootglobal.asax    Line: 5
Stack Trace:
[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpContext.get_Request() +3467061
   ASP.global_asax.Application_Start(Object source, EventArgs e) in c:inetpubwwwrootglobal.asax:5

[HttpException (0x80004005): Request is not available in this context]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3388766 …
This error is due to a design change in the IIS7 Integrated pipeline that makes the request context unavailable in Application_Start event.  When using the Classic mode (the only mode when running on previous versions of IIS), the request context used to be available, even though the Application_Start event has always been intended as a global and request-agnostic event in the application lifetime.  Despite this, because ASP.NET applications were always started by the first request to the app, it used to be possible to get to the request context through the static HttpContext.Current field.
Applications have taken a dependency on this behavior become broken in Integrated mode, which officially decouples Application_Start from the request that starts the application.  In the future, we may introduce changes that will further break the assumption that applications start because of requests – for example, by introducing a warmup mechanism that can start ASP.NET applications based on a specific schedule.
So, what does this mean to you?
Basically, if you happen to be accessing the request context in Application_Start, you have two choices:
  1. Change your application code to not use the request context(recommended).
  2. Move the application to Classic mode (NOT recommended).
In fact, most of the customers I have spoken to realize that they do not need to access the request context in Application_Start.  Because this event is intended for global initialization activities, any logic that references a specific request is typically a design oversight.
In these cases, it should be trivial to remove any reference to HttpContext.Current from the Application_Start method. 
A common example of this is using theHttpContext.Current.Request.ApplicationPath to get to the application’s root virtual path.  This should become HttpRuntime.AppDomainAppVirtualPath.  Voila, no need to use the request!
In the cases where you do need to access the request information for the first request to the application (I have seen VERY few applications where this is the case), you can use a workaround that moves your first-request initialization from Application_Start to BeginRequest and performs the request-specific initialization on the first request.
Here is an example of how to do that in your global.asax (you can also do it in a module):
void Application_BeginRequest(Object source, EventArgs e)
{
    HttpApplication app = (HttpApplication)source;
    HttpContext context = app.Context;
    // Attempt to peform first request initialization
    FirstRequestInitialization.Initialize(context);
}

class
FirstRequestInitialization
{
    privatestaticbool s_InitializedAlready = false;
    privatestaticObject s_lock = newObject();
    // Initialize only on the first request
    publicstaticvoid Initialize(HttpContext context)
    {
        if (s_InitializedAlready)
        {
            return;
        }
        lock (s_lock)
        {
            if (s_InitializedAlready)
            {
                return;
            }
            // Perform first-request initialization here …
            s_InitializedAlready = true;
        }
    }
}
This code attempts to initialize at the beginning of each request, with only the first request performing the initialization (hence, first request initialization J). Note that the lock is necessary to insure correct behavior in the case where multiple requests arrive to your application near simultaneously (don’t lock around type objects, since this may lock multiple appdomains).
With this issue out of the way, you should be able to enjoy the benefits of Integrated mode on IIS7 without much other grief.  

Wednesday, 29 July 2015

Differences between Sql server 2005, 2008, 2008r2, 2012

Difference between Sql server 2000 and 2005
Table1

Difference between Sql server 2005 and 2008
Table2

Difference between Sql server 2008 and 2008r2
Table3

Difference between Sql server 2008 and 2012
Table4

Tuesday, 28 July 2015

VSS 6 get latest version window does not show



You may have inadvertently ticked the option to not show the dialog box. Try holding down the Shift key while clicking Get Latest Version. This should force the dialog to appear. 


 

You can then uncheck the 'Only show this dialog when Shift key is down' checkbox to    ensure you don't have to hold down Shift every time.

 

Thursday, 25 June 2015

Displaying Dynamic Columns in SSRS Report

Problem: How to display selected columns dynamically in SSRS reports.

Example: A report contains more than 30 fields. Some users want to see only 5 fields, some users 10 fields, and other may want to see 20 fields.
Solution: Add a Report Parameter having the values as the name of all the fields of dataset. Now set hidden expression for each column of the tabular report.

Here is the solution with an example:

STEP1:
Create a report with required dataset. Drag and drop table control and select dataset fields.
In my example, I have following fields in the dataset: Year, Quarter, Month, Date, Product Name, Customer Name, Sales Region, Sales Country, Order Number, Sales Amount.

STEP2:
Create a dataset dsColumns using below query:
SELECT 1 ID, 'Year' AS ColumnName UNION
SELECT 2 ID, 'Quarter' AS ColumnName UNION
SELECT 3 ID, 'Month' AS ColumnName UNION
SELECT 4 ID, 'Date' AS ColumnName UNION
SELECT 5 ID, 'Product Name' AS ColumnName UNION
SELECT 6 ID, 'Customer Name' AS ColumnName UNION
SELECT 7 ID, 'Sales Region' AS ColumnName UNION
SELECT 8 ID, 'Sales Country' AS ColumnName UNION
SELECT 9 ID, 'Order Number' AS ColumnName UNION
SELECT 10 ID,'Sales Amount' AS ColumnName


STEP3:
Create a new parameter with name pDisplayFields and Promt Display Columns as shown below:
In Available Values of Report Parameter Properties wizard, select Get values from a query, select dsColumns in Dataset, ColumName in value field and label field.

In Default Values of Report Parameter Properties wizard, select Get values from a query, select dsColumns in Dataset, ColumName in value field.

STEP4:
Now you have to set the expression to display the colummns which are selected in the pDisplayColumn parameter. Right click on First Column (Year in my example) and click Column Visibility...
Write following expression in Show or hide based on an expression of Column Visibility wizard:
=IIF(InStr(JOIN(Parameters!pDisplayFields.Value,","),"Year")>0,False,True)

Now repeat this expression for all the columns by modify the expression for the respective column name accordingly.

Thats all. Now preview the report. You will see all the columns by default.



Now select required columns in Display Column parameter to modify the report layout at run time.

Tuesday, 14 October 2014

User friendly CAPTCHA for Asp.Net MVC

In this post I will show you how to add CAPTCHA functionality to a html form in an Asp.Net MVC 4 project. My goal is to make the CAPTCHA problem easy enough for all to solve, like a simple sum operation, and easier to read then the standard CAPTCHA text. An easy to read image is more vulnerable to smart bots that have an ORC system but I prefer to scare less clients then to provide the strongest anti-bot protection. And one more feature, when clicked the image should, change giving the users a new chance to respond correctly.


Implementing CAPTCHA in C# and MVC 4 takes these steps:
  • Create an Action that returns a CAPTCHA image and stores in the user session the right answer
  • Add to your Model a string property named Captcha
  • Add to your View the textbox for Captcha and the image placeholder
  • Validate answer inside your own Action

Render CAPTCHA image
CaptchaController.cs
        public ActionResult CaptchaImage(string prefix, bool noisy = true)
        {
            var rand = new Random((int)DateTime.Now.Ticks);
            //generate new question
            int a = rand.Next(10, 99);
            int b = rand.Next(0, 9);
            var captcha = string.Format("{0} + {1} = ?", a, b);

            //store answer
            Session["Captcha" + prefix] = a + b;

            //image stream
            FileContentResult img = null;

            using (var mem = new MemoryStream())
            using (var bmp = new Bitmap(130, 30))
            using (var gfx = Graphics.FromImage((Image)bmp))
            {
                gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                gfx.SmoothingMode = SmoothingMode.AntiAlias;
                gfx.FillRectangle(Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height));

                //add noise
                if (noisy)
                {
                    int i, r, x, y;
                    var pen = new Pen(Color.Yellow);
                    for (i = 1; i < 10; i++)
                    {
                        pen.Color = Color.FromArgb(
                        (rand.Next(0, 255)),
                        (rand.Next(0, 255)),
                        (rand.Next(0, 255)));

                        r = rand.Next(0, (130 / 3));
                        x = rand.Next(0, 130);
                        y = rand.Next(0, 30);

                        gfx.DrawEllipse(pen, x – r, y – r, r, r);
                    }
                }

                //add question
                gfx.DrawString(captcha, new Font("Tahoma", 15), Brushes.Gray, 2, 3);

                //render as Jpeg
                bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);
                img = this.File(mem.GetBuffer(), "image/Jpeg");
            }

            return img;
        }
If you want to use multiple  CAPTCHAs you can use the prefix to store the answer for each form. Much can be improved regarding the rendered image, for example I could use different font and size for each number in the equation, replace the noise with text distortion.
Include  CAPTCHA validator in Model and View
Models.cs
    public class SubscribeModel
    {
        //model specific fields
        [Required]
        [Display(Name = "How much is")]
        public string Captcha { get; set; }
    }
In the View, beside a label, textbox and validator span you’ll need to add an image placeholder for the CAPTCHA.
Index.cshtml
@*form specific fields*@ <div class="editor-label">
    @Html.LabelFor(model => model.Captcha)
    <a href="@Url.Action("Index")">
        <img alt="Captcha" src="@Url.Action("CaptchaImage")" style="" />
    </a>
</div> <div class="editor-field">
    @Html.EditorFor(model => model.Captcha)
    @Html.ValidationMessageFor(model => model.Captcha)
</div>
Validate CAPTCHA on the server side
Inside your post action where the form submits you can validate the answer by comparing with the session value.
CaptchaController.cs
[HttpPost] public ActionResult Index(SubscribeModel model)
{
    //validate captcha
    if (Session["Captcha"] == null || Session["Captcha"].ToString() != model.Captcha)
    {
        ModelState.AddModelError("Captcha", "Wrong value of sum, please try again.");
        //dispay error and generate a new captcha
        return View(model);
    }
    return RedirectToAction("ThankYouPage");
}

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...