SSIS: How to pass variables to ADO.NET Source

Hey,  Trouble in mapping parameter or vaiable? This should be fairly a simple thing to do, why the SSIS Designer is showing so many issues ?. If you are one among those asking that question, hope this post will help you.

This post is about mapping a variable in any SSIS data elements, i.e ADO.NET Data Source, SQL tasks ,OLE DB source etc.

To use expressions for an ADO.NET source in a data flow, here are a few simple steps:

Step 1 – Go to the Data Flow Task Properties window

On the Control Flow tab (not the Data Flow tab), right-click the Data Flow Task you are working on and select Properties.

ssis-ctrlflow-menu

Step 2 – Open the Property Expression Editor

In the Properties window, find a property called Expression and a small button next to it. Click the button to open the Expression Editor.

ssis-ctrlflow-menu3


Step 3 – Open the Expression Builder for SQL Command

In the Property list, select [ADO NET Source].[SqlComamnd] and click the button next to the Expression column to open Expression Builder.

Step 4 – Write query with variables

Start to write your query with variable names and click the Evaluate Expression button to test the expression.

Example : “Select col1,col2,col3 from Table Where id=” +  @[User::ParamId]

ExpressionBuilder

You may get an error “the data types dt_wstr and dt_i4 are incompatible for binary operator +” , if an incompatibledata type used for concatenation.

Either cast the variable a string or convert variable type to String for concatenation operation.

“Select col1,col2,col3 from Table Where id=” + (DT_WSTR,10) @[User::ParamId]

By default variable will be created as Boolean, to convert check variable type expand the variable explorer window. Visual Studio. Menu SSIS >> Variables

ssis-var-menu

Note: You can change the DelayValidation property to true, so you do not need to provide an initial value to the variable holding the parameter value, otherwise the package could fail validation.

Reference:

How to: Map Query Parameters to Variables in an Execute SQL Task

http://msdn.microsoft.com/en-us/library/ms140355(v=sql.105).aspx

Difference when using an expression Vs Parameters:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2415979&SiteID=1

Thanks for reading. Hope this help

Posted in SSIS | Tagged , , | Leave a comment

Learn .NET Core

Posted in ASP.NET, c#, Follow along series, netcore | Tagged , , , , , , , , , , | Leave a comment

Chrome Error code: ERR_UNSAFE_PORT This webpage is not available

Hello,

This post about an issue I faced while debugging an asp.net mvc application in Google Chrome. (Version 40.0.2214.111 m). I bulit my website using MVC 4 Template in Visual Studio 2010, designed a top menu and started testing the UI. By default visual studio was opening up the homepage in IE 🙂 , everything was running as expected, so just to see how it works in Chrome, I opened IIS Express url (localhost:6000), and the below error shown up “This webpage is not available“.

CHROME_ERR_UNSAFE_PORT

Show details link revealed more info Chrome Error code: ERR_UNSAFE_PORT

Alright it looks like not all ports are supported by the chrome browser. This is because of Chrome restricting the local ports.

How To fix the issue

1. Change Website Port setting in Visual Studio (Recommended) OR

2. Add the testing port(here 6000) as an allowed port to Google Chrome Explicitly

How To Change Website Port setting in Visual Studio

1. Right click your website project in the solution, select properties, select “Web” Tab in the Servers Section/Use Visual Studio Development Server, Specific Port give a random port no that is not used by any other application in your machine.

WebsitePortSetting

How to allow port in Google Chrome explicitly :

Right click on the chrome shortcut (Desktop/StartMenu/Quick Launch) -> Properties -> Change the target:

“C:\Program Files (x86)\Google\Chrome\Application\chrome.exe” –explicitly-allowed-ports=81,84,87

New shortcut command should like this , if Chrome is installed on the default installation location.

Continue reading

Posted in ASP.NET, IIS | Tagged , , | Leave a comment

IIS HTTP Error 503. The service is unavailable

Hi, Setting up a new virtual directory/application in IIS, Is it giving this wired error when you try to browse to localhost saying “HTTP Error 503. The service is unavailable.” ? Don’t just give up, you can try the below step to fix the issue.

1. Check if the application pool is not started/enabled for the website in IIS.

2. Check whether the identity assigned to the application pool is not active and uses the correct password. Sometimes Developers use their own LogInId as appPool Id and change password later point. This happened to me 🙂

3. Check whether the identity has access to physical folder the Virtual directory is pointed to.

4. Enable Failed Request Tracing Rules and see log if anything is getting generated.

How to check application pool status ?

Step 1: Start > Run > type “inetmgr”, the command open IIS

Step 2: Locate your application/Virtual directory.Capture-http501.1

Step 3: Look for the application pool of the selected website.Capture-http501 apppool

Step 4: Select the Application Pool and click on the Action Bar on the right side, Edit Application Pool Section Advance Settings Link.

Capture-apppol identity

Step 5: Verify the identity mentioned in Process Model Section Identity Textbox is active and uses the correct password, click on the right side of Identity Textbox in case you want to change the id/password.

Capture-app pool id
Step 6: Now go back to Application pool list window, Right click on the application pool name in the Application Pool list and then select the Start option from the context menu.

Step 7: Also check the identity has access the physical path to which the the virtual directory. If the error wouldn’t get resolved after performing steps  1 to 6.

Thanks for reading, Happy Coding!

Posted in ASP.NET, IIS | Tagged , | Leave a comment

Difference between var and let variable declaration is the “scope”

Main difference between var and let variable declaration is the “scope”.
var is scoped to the nearest function block.

let is scoped to the nearest enclosing block, this scope can be smaller than a function block.

var topic = “FirstValue”;

if (topic) {
let topic = “value inside if”;
console.log(“block”, topic); // block value inside if
}

console.log(“global”, topic); // global FirstValue

Try JSFiddle here

With the let keyword, we can scope a variable to any code block. Using let protects the value of the global variable. Both types will have global scope if defined outside a function block, no difference work exactly same way

Scope: {Global} Example

let letValue = 'Value for let variable'; //globally scoped
var varValve = 'Value for var variable'; //globally scoped
function FirstFunction()
{
//letValue & varValve are visible here
}
function secondFunction()
{
//letValue & varValve are visible here
}
//letValue & varValve are visible here

Also, just like var, variables declared with let are visible before they are declared in their enclosing block.
Scope: {function} Example
They are identical when used like this in a function block.


function getValueFunction() {
let letValue = 'Value for let variable'; //function block scoped
var varValve = 'Value for var variable'; //function block scoped

//letValue & varValve are visible here

};//--&gt; <span style="color:#0000ff;">nearest enclosing block, let scope ends here</span>**

//letValue &amp; varValve are <span style="color:#ff0000;"><strong>NOT</strong> </span>visible here

Scope: {Block} Example
Here is the difference. let is only visible in the for() loop and var is visible to the whole function.


<code>function testMethod1() {
//letValue is NOT visible out here</code> for( let letValue = 0; letValue &lt; 5; letValue++ ) { //letValue is only visible in here (and in the for() parentheses) };<span style="color:#0000ff;">//--&gt; nearest enclosing block, let scope ends here**</span> //letValue is <span style="color:#ff0000;">NOT</span> visible out here }; 

var is visible in the scope,  that is the nearest function block

function testMethod2() {
//varValve is visible out here</pre>
for( var varValve = 0; varValve &lt; 5; varValve++ ) { //varValve is visible to the whole function }; <span style="color:#0000ff;">//varValve is visible and is scoped to the nearest function block</span> };//--&gt;nearest function block ends 

And let can also be used to create its own enclosing block.


function testMethod3() {
//letValue is NOT visible out here

let( letValue = 'now' ) {

//letValue is only visible in here

};<span style="color:#0000ff;">//--&gt;nearest enclosing block ends</span>

//letValue is <span style="color:#ff0000;">*not*</span> visible out here
};

Hence, let keyword works very much like var. The main difference is that the scope of a var variable is the entire enclosing function.

ECMAScript is the standard and let is included in the 6th edition draft and will most likely be in the final specification. Fortunately 😉 IE11 added support for let msdn.microsoft.com/en-us/library/ie/dn342892%28v=vs.85%29.aspx

The kangax compatibility table is a great place to stay informed about the latest JavaScript features and their varying degrees of support by browsers.

 

Posted in javascript | Tagged , | Leave a comment

SharePoint GetListItems using JQuery and $().SPServices

Hello Reader,

This post is about a very useful SharePoint JQuery Library.

logo

Logo is taken from: http://spservices.codeplex.com/

I have used this library to build Custom SharePoint Page to generate a monthly report page that will list a set of approved request for a selected month.

So here the step by step explanation of how I did it.

Components Used

1. SharePoint Custom List

2. SharePoint Custom HTML Page

3. Javascript Libraries : JQuery, SPServices, DateJS

SP List definition is as follows

Column (click to edit) Type Used in
Employee No Single line of text Item
Task Description Single line of text Item
Estimated Work Hours Number Item
Approval Status Choice Item
PM Approval Choice Item
Project Code Single line of text Item
Project Manager Person or Group Item
Cost Centre Single line of text Item
Created By Person or Group
Modified By Person or Group

4. Three Share point Forms to override the default New/Edit/View Page

5. One HTML form for the Site Owner/Approver to edit or approve an entry.

6. Custom Report Page which will show approved entries for the selected month.

Following are the main the client side methods in the Report Page:

$(document).ready() => page load event does the following things

1. Create a dropdown list with current and past 5 months.

I have used Datejs, this is an open source JavaScript Date library for parsing, formatting and processing.

googlecode-header

Source: https://code.google.com/p/datejs/

 

2. Attached an on change event on the Month dropdownlist, which will pull the list data for the selected month from the above Sharepoint List using SPServices library methods

 

3. A method to query the SharePoint List to get the approved items for the selected month,  $().SPServices made my job easy, thanks a lot Marc D Anderson & Team.

 


$(document).ready(function() {
populatMonthDDL();
GetApprovedItems();
});

function GetApprovedItems(){

var titleField = "<FieldRef Name='Title' />";
var datField = "<FieldRef Name='Date' />";
var statusField = "<FieldRef Name='Status' />";
var createdByField = "<FieldRef Name='Author' />";
var pmField = "<FieldRef Name='Project_x0020_Manager' />";

var viewFields = "<ViewFields>" + titleField + datField + pmField + statusField
+ createdByField + "</ViewFields>";

var ifApproved = "<Eq><FieldRef Name='Status'/><Value Type='Text'>Approved</Value></Eq>";
var GeqSelectedMonth = "<And><Geq><FieldRef Name='Date'/><Value Type='DateTime'>" + selectedMonth + "</Value></Geq>";
var LeSelNextMonth = "<Lt><FieldRef Name='Date'/><Value Type='DateTime'>" + NextMonth + "</Value></Lt></And>";

var queryText = "<Query><Where><And>" + ifApproved + GeqSelectedMonth + LeSelNextMonth + "</And></Where></Query>";
$().SPServices({
operation: "GetListItems",
async: false,
listName: "CustomRequestList",
CAMLViewFields: viewFields,
CAMLQuery: queryText,
completefunc: populateData
});
}

Don’t worry about writing long CAML query and debugging it at client side, you can use Simple CAML Query to write, test and make your query perfect.

Source: http://www.sharepointhillbilly.com/Lists/Posts/Post.aspx?ID=8

Be careful while mentioning the List Field names

The column names should be the InternalNames for the columns, which might look like “My_x0020_Column”, as special characters like spaces are encoded. In this case, the space becomes “_x0020_” because a space is ASCII character 20 (hexadecimal). Seehttp://www.asciitable.com/ for more info.

The easiest way to identify the InternalName for a column is to go to the List [or Library] Settings, click on the column name, and look on the end of the URL, which will end with something like this in SharePoint 2007:

/_layouts/FldEditEx.aspx?List={37920121-19B2-4C77-92FF-8B3E07853114}&Field=Sales_x0020_Rep

or this in SharePoint 2013:

/_layouts/15/FldEdit.aspx?List={F3641DF3-80A2-4BBA-A753-E6BFB3FD98E4}&Field=ImageCreateDate

Your column’s InternalName is at the end of the URL after “Field=”.

Note that regardless what you specify in the CAMLViewFields, you will get some additional columns even though you don’t want them, including the item’s ID.

Source: http://sympmarc.com/2013/10/16/single-page-applications-spas-in-sharepoint-using-spservices-part-2-getlistitems/

 

4. Finally a small piece of java script to format the page,  div containing the list data will be visible, script will hide SharePoint Mater Page and other page elements while printing. This event is attached to a print button on the page onclick = “printContent(‘reportDIV’)”


var isPrinting = false;
function printContent(el){

var container = document.getElementById(el),
origDisplay = [],
origParent = container.parentNode,
body = document.body,
childNodes = body.childNodes,
i;

if (isPrinting ) { return;}// block the button while in printing mode
isPrinting = true;

for (i = 0; i < childNodes.length; i++) {// hide all body content
var node = childNodes[i];
if (node.nodeType === 1){
origDisplay[i] = node.style.display;
node.style.display = "none";
}
}

body.appendChild(container);
window.focus();
var onPrintFinished=function(printed){ //function triggers when window.print() is finished
origParent.appendChild(container); // put the masterpage and other content back in
for (i = 0; i < childNodes.length; i++) {
var node = childNodes[i];
if (node.nodeType === 1) {
node.style.display = origDisplay[i];
}
}
isPrinting = false;
}
onPrintFinished(window.print());//Execute print command
}

Hope this will help someone. Thanks for reading 🙂

Posted in $().SPServices, sharepoint | Tagged , , , | Leave a comment

The only source…

The only source of knowledge is experience.

A giant ship engine failed. The ship’s owners tried one expert after another, but none of them could figure but how to fix the engine.

Then they brought in an old man who had been fixing ships since he was a young. He carried a large bag of tools with him, and when he arrived, he immediately went to work. He inspected the engine very carefully, top to bottom.

Two of the ship’s owners were there, watching this man, hoping he would know what to do. After looking things over, the old man reached into his bag and pulled out a small hammer. He gently tapped something. Instantly, the engine lurched into life. He carefully put his hammer away. The engine was fixed!

A week later, the owners received a bill from the old man for ten thousand dollars.

“What?!” the owners exclaimed. “He hardly did anything!”

So they wrote the old man a note saying, “Please send us an itemized bill.

The man sent a bill that read:

Tapping with a hammer………………….. $ 2.00

Knowing where to tap…………………….. $ 9,998.00

Effort is important, but knowing where to make an effort makes all the difference!

Read more at http://www.brainyquote.com/quotes/topics/topic_experience.html#j8u5OV6OHUUiUX8C.99

Posted in Quotes | Leave a comment