Tuesday, February 9, 2016

jQuery UI Library - necessary jQuery file and version

The latest versions of QueryUI library have some quirks to note when adding its necessary references in the section. Below is examples that work and examples that do not work.

Basically when using jQuery UI version 1.11.4 or later, do not use jQuery version 2.x.x. Use jQuery version 1.10.x ~ 1.12.x without the jquery-migrate library.

// Works!
<link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css">
<script type="text/javascript" src="jquery-1.12.0.js"></script>
<script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>

// Works!
<link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css">
<script type="text/javascript" src="jquery-1.10.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>

// Does Not Work!
<link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css">
<script type="text/javascript" src="jquery-1.12.0.js"></script>
<script type="text/javascript" src="jquery-migrate-1.2.1.js"></script>
<script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>

// Does Not Work!
<link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css">
<script type="text/javascript" src="jquery-1.10.2.js"></script>
<script type="text/javascript" src="jquery-migrate-1.2.1.js"></script>
<script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>

// Does Not Work!
<link rel="stylesheet" href="jquery-ui-1.11.4/jquery-ui.css">
<script type="text/javascript" src="jquery-2.1.4.js"></script>
<script type="text/javascript" src="jquery-ui-1.11.4/jquery-ui.js"></script>

Thursday, February 4, 2016

RDLC on WebForm CodeBehind example

Below is a complete source code of a RDLC rendering on aspx webform page.

One important thing to note is that when parameter is used to perform a calculation within the report, the parameter needs to be supplied to the RDLC local report inside ReportViewer. This was a tricky part to understand: I wanted to grab the parameter value from the querystring and feed it directly into a stored procedure in the code-behind, so that I can generate the dataset under the matching "dataset name" embedded in the RDLC report. However, even though the RDLC does not actually use the parameter value to perform query on its own, I still needed to supply the parameter value to the RDLC report separately from feeding it to the stored procedure in the code-behind. Without doing this, the RDLC report would show blank screen.

Another important thing to use is the "SetBasePermissionsForSandboxAppDomain( )" function to allow the local report in ReportViewer to have enough permission so that it is rendered properly.

// RDLC on Webform ("RRA_fax.aspx.cs")
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Security;
using System.Security.Permissions;
using Microsoft.Reporting.WebForms;
using System.Configuration;
using COR.WEB.Helpers;

namespace COR.WEB.Reports
{
    public partial class RRA_fax : System.Web.UI.Page
    {
        int productID;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                initQueryString();
                initReport();
            }
        }

        protected void initQueryString()
        {
            Int32.TryParse(Request.QueryString["ProductID"], out productID);
        }

        protected void initReport()
        {
            string connStr = ConfigurationManager
                .ConnectionStrings["MyConnString"].ConnectionString;
            
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                using (SqlCommand cmd = new SqlCommand("proc_ProductDetails", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    // supplying querystring value as parameter
                    cmd.Parameters.AddWithValue("@productID", productID);

                    using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
                    {
                        DataSet dataSet = new DataSet();
                        adapter.Fill(dataSet);
                        
                        // ds_ProductDetails is the dataset name in RDLC file.
                        ReportDataSource rds1 = 
                            new ReportDataSource("ds_ProductDetails", dataSet.Tables[0]);

                        ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(
                            new PermissionSet(PermissionState.Unrestricted));
                        ReportViewer1.SizeToReportContent = true;   
                     
                        ReportViewer1.LocalReport.ReportPath = 
                            Server.MapPath("~/RDLC/ProductDetails.rdlc");
                        // important! - if RDLC originally has a parameter, 
                        // we still have to provide a value for it,
                        // even though the RDLC does not actually use it 
                        // to perform a query.
                        ReportParameter param1 = 
                            new ReportParameter("productID", productID.ToString());
                        ReportViewer1.LocalReport.SetParameters(param1);

                        ReportViewer1.LocalReport.DataSources.Clear();
                        ReportViewer1.LocalReport.DataSources.Add(rds1);

                        ReportViewer1.LocalReport.Refresh();
                    }
                }
            }
        }
    }
}

Render page in different IE version mode

IE 11 has the edge mode set as default rendering engine. Going forward, IE 11 seems to be breaking away with some of the backward-compatible.

I have run into issues with RDLC reports. The letterhead logos are embedded into the report files. They would only appear normally when rendered in IE 9 or 10 mode. A vertical line appears instead when the report is rendered in IE 5, 7, 8 and Edge-mode.

In order to have IE 11 to render the images on the page that contains RDLC report, we can use meta tag as follows to force IE to select a desired version.

<configuration> 
  ...
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=edge" />
        <!-- To force IE to render in edge mode. IE=9, IE=10, etc can be used, too. -->
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

Monday, January 25, 2016

RDLC report error on MVC/Webform hybrid website: The Value expression for the query parameter contains an error : Request for the permission of type System.Security.Permissions.SecurityPermission failed.

When creating RDLC report on MVC/Webform hybrid website, the following error can occur.

The Value expression for the query parameter contains an error : Request for the permission of type System.Security.Permissions.SecurityPermission failed.

Quick workaround to address this issue is by setting up permission on local report like below.

// Default.aspx.cs
...
using System.Security;
using System.Security.Permissions;

namespace MyProj.Web.Reports
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if(!Page.IsPostBack)
    {
      ...
      ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RDLC/Report1.rdlc");
      ReportViewer1.LocalReport.SetBasePermissionsForSandboxAppDomain(
        new PermissionSet(PermissionState.Unrestricted));
      ReportViewer1.LocalReport.Refresh();
    }
  }
}

Friday, January 22, 2016

Remove Password Change Requirement in AD

For test AD environment, it is often convenient to disable the default password requirements such as minimum length, expiration days, etc. Here's a quick cheat sheet on how to do it.


  1. Remote in to Domain Controller
  2. Run "Group Policy Management"
    1. Expand Forest, Domains and your AD domain
    2. Right-click the "Default Domain Policy" and select "Edit"
    3. Group Policy Management Editor appears.
      1. Expand Computer Configuration
      2. Expand Policies
      3. Expand Windows Settings
      4. Expand Security Settings
      5. Expand Account Policies
      6. Select Password Policy
        1. Enable policies with 0 values as needed in the right pane.
      7. Select Account Lockout Policy
        1. Make changes as needed.
  3. On Windows 2012 or later
    1. Use Powershell command "Invoke-GPUpdate"
  4. On Windows 2008 or earlier
    1. Use command "gpupdate /force"

Tuesday, December 29, 2015

WEBCONFIG.ACCSRV.XML does not have element "configuration/configSections/sectionGroup[@name='SharePoint']" or it is invalid

I recently updated SharePoint 2013 environment using the December 2015 CU packages and ran into an error. There are two (2) SharePoint 2013 servers in the environment. One Web-Front-End SharePoint Server and one Service Application SharePoint Server. On the Service Application Server, the following error message appeared during step 8 of SharePoint Products Configuration Wizard, which I ran after installing all December 2015 CU successfully.

Configuration Failed
...
Failed to install the application content files.
An exception of type System.IO.InvalidDataException was thrown. Additional exception information: The web configuration file, C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\config\WEBCONFIG.ACCSRV.XML, does not have element "configuration/configSections/sectionGroup[@name='SharePoint']" or it is invalid.

First I stopped Access Database Service 2010 and Access Services from the Application Service Server and then ran the Config Wizard again. It did not make a difference.

Then I stopped all services except "SharePoint Server Search" on the Application Service Server and ran the Config Wizard. It completed without error only then.

The following are the list of services I stopped on the Application Service Server.
  • Access Database Service 2010
  • Access Services
  • App Management Service
  • Business Data Connectivity Service
  • Central Administration
  • Claims to Windows Token Service
  • Distributed Cache
  • Document Conversions Launcher Service
  • Document Conversions Load Balancer Service
  • Excel Cacluation Services
  • Lotus Notes Connector (was never turned on)
  • Machine Translation Service (was never turned on)
  • Managed Metadata Web Service
  • Microsoft SharePoint Foundation Incoming E-Mail
  • Microsoft SharePoint Foundation Sandboxed Code Service
  • Microsoft SharePoint Foundation Subscription Settings Service
  • Microsoft SharePoint Foundation Web Application
  • Microsoft SharePoint Foundation Workflow Timer Service
  • PerformancePoint Service
  • PowerPoint Conversion Service
  • Search Host Controller Service
  • Search Query and Site Settings Service
  • Secure Store Service
  • User Profile Service
  • User Profile Synchronization Service
  • Visio Graphics Service
  • Word Automation Services
  • Work Management Service

Also, the lesson I learned was that in SharePoint 2013, it would be best to turn on only the absolutely necessary services or service applications and turn off the ones if they are not absolutely necessary for the sake of the best predictable results in patch installation. 

Thursday, October 22, 2015

One-to-one foreign key relationship in Entity Framework

This site seems to have useful contents for those who want to re-visit their knowledge about Entity Framework.

The example on "One-to-One or One-to-Zero Foreign Key Relationship" was especially useful.

Take a look.

Site Url = http://www.EntityFrameworkTutorial.net