February 20, 2010

Iterating over JSON object (string ) with jquery

We had a scenario where in we need to search for particular object in collection. Whenever the user changes something in dropdown in ASP.NET we need to show some value in a label. If we take the drop down value to server it would take time.... so what we thot is we searialized the object using JavascriptSerializer in ASP.NET and converted to JSON string.. passsed to a javascript function to search.... (whenever dropdown changes)... I was literally amazed with the power of JSON and jquery combination... thot i would share with people in need.....

Here is the JSON string...in Javascript...

var obj = [{"Description":"No jquery pricing group may be used for Testing", "ID":1, "TempID":1, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":2, "TempID":2, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":3, "TempID":3, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":4, "TempID":4, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":5, "TempID":1, "CompareID":4}, {"Description":"Jquery required for pricing Testing", "ID":6, "TempID":2, "CompareID":4}, {"Description":"Jquery required for pricing Testing", "ID":7, "TempID":3, "CompareID":4}, {"Description":"Jquery required for pricing Testing", "ID":8, "TempID":4, "CompareID":4}, {"Description":"No jquery pricing group may be used for Testing", "ID":9, "TempID":1, "CompareID":5}, {"Description":"Jquery required for pricing Testing", "ID":10, "TempID":2, "CompareID":5}, {"Description":"Jquery required for pricing Testing", "ID":11, "TempID":3, "CompareID":5}, {"Description":"Jquery required for pricing Testing", "ID":12, "TempID":4, "CompareID":5}];

We had a requirement to searhch the description for matching TempID and COmpareID...

Our Javascript function was amazingly...

function Myfunc(ID1,Exp1){jQuery.each(obj, function Test(x) { if (obj[x].TempID == ID1 && obj[x].CompareID == Exp1) //return obj[x].Description; alert(obj[x].Description);}); }

This would have helped you to understand the power of jqeury

January 16, 2010

ASP.NET Dynamic User controls

Today after long time...I moved to an assignment to work in ASP.NET after the gap of almost nealry 5 years. I started working on an Intranet Portal for a financial institution.

We wanted to generate certain UIs dynamically, we chose different user controls will be loaded based on the user requirement. One thing I learned today is "Dynamic Controls Should be Loaded on Each PostBack" On every postback literally you need to load the controls again and again. If you want the control to have its Viewstate data preserved, adding the USercontrols to page (Parent) should happen before LoadViewstate event gets fired in the page life cycle.

Normally the user controls will be added as Controls.Add(UsercontrolPath), where ocntrols is Place holder in the page/another user control.

I will write more about this assignement that looks very interesting.

January 5, 2009

Meta Data Queries in SQL Server 2000

-- Query to Find All User Tables

SELECT * FROM SYSOBJECTS SOWHERE SO.XTYPE = 'U' ORDER BY SO.NAME

-- Query to Find All User Views

SELECT SO.NAME FROM SYSOBJECTS SOWHERE SO.XTYPE = 'V' ORDER BY SO.NAME

--Query to Find all Procedures in the DB

SELECT SO.NAME FROM SYSOBJECTS SOWHERE SO.XTYPE = 'P' ORDER BY SO.NAME

--Query to Find all Triggers in the DB

SELECT SO.NAME FROM SYSOBJECTS SOWHERE SO.XTYPE = 'TR' ORDER BY SO.NAME

--Query to Find all User Defined Table Functions in the DB

SELECT SO.NAME FROM SYSOBJECTS SOWHERE SO.XTYPE = 'TF' ORDER BY SO.NAME

--Query to Find all User Defined Inline Functions in the DB

SELECT SO.NAME FROM SYSOBJECTS SOWHERE SO.XTYPE = 'IF' ORDER BY SO.NAME

--Query to Find all User Defined Scalar Functions in the DB

SELECT SO.NAME FROM SYSOBJECTS SOWHERE SO.XTYPE = 'FN' ORDER BY SO.NAME

Note.
X.Type define the object type, the possible values are
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
IF = Inlined table-function
P = Stored procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure

December 2, 2008

SSIS - Script Component - Variables Access Error

I was developing an SSIS package and I encountered the following problem.
I had a OLE DB source that is providing me data from a SQL table in my data flow task. I had a script component following it. I am trying to concanctenate my one of the string column to a variable and trying to use it in other task.
So I had my code like this in my inputprocessrow method.
--------------------------------------------------------------------------------------
While Row.NextRow
myval = myval + " , " + Row.customer
End While
----------------------------------------------------------------------------------------
And i was trying to set the local variable value to my Pacakge variable collection and I encountered following error.
"The collection of variables locked for read and write access is not available outside of Post Execute", which drove me mad.

After googling for some time got this info.

You need to have a PostExecute method and try assigning it there.

-------------------------------------------------------------------------------------
Public Overrides Sub PostExecute()
Variables.Customers = myval
MsgBox("Variable Values is " + Variables.Customers)
MyBase.PostExecute()
End Sub
-------------------------------------------------------------------------

July 10, 2008

SQL Injection Tip

Hope everyone is aware of SQL Injection attacks. For people who are new, it is something about intruding in to your SQL Server (DB) by passing some commands through a request.

If the following (0x73656C656374206E616D652066726F6D207379732E6461746162617365733B) value is passed to the SQL Query, it will list all the DBs on the server. Something interesting. So whenever you get a request, check for it.

June 17, 2008

Service Broker - An Alternate to Messaging MS SQL Server

1. Enable Service Broker in the DB.
Use Master;
Go
ALTER DATABASE AdventureWorks SET ENABLE_BROKER;
go

2. Create Endpoint to send / receive messages from outside of SQL Server Instance.
- Create Endpoint with Port number and authentication level
Use Master;
go
CREATE ENDPOINT ExampleEndPoint
STATE = STARTED
AS TCP ( LISTENER_PORT = 3133)
FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS KERBEROS);
go

Once Service Broker in STARTED state it will send /receive Messages. To stop either deacticate / pause

Use Master;
Go
ALTER ENDPOINT ExampleEndPoint
STATE = STOPPEDl
Go

To start again
Use Master;
Go
ALTER ENDPOINT ExampleEndPoint
STATE = STARTED
Go

3. TO Forward Message from One instance to another you need to have service endpoint started and follow the below syntax to Enable /disable forwarding. The Size mentioned is in MB

Use Master;
go
ALTER ENDPOINT ExampleEndPoint
FOR SERVICE_BROKER (MESSAGE_FORWARDING = ENABLED, MESSAGE_FORWARD_SIZE = 15);
go

Use Master;
go
ALTER ENDPOINT ExampleEndPoint
FOR SERVICE_BROKER (MESSAGE_FORWARDING = DISABLED);
go

4.Message Transport
BABP (Binary Adjacent Broker Protocol) and Dialog Protocol.
BABP - Basic message Transport, Bi-directional and multiplexed. Role to send messages.
Dialog - handles end to end communication and message ordering as a one-time-only in order delivery system. authenitcation and encryption is responsibility.

Steps to Create SErvice Borker:

1. Define Message Type and Validation
2. Define Contract
3. Create 2 queues sender and receiver
4. Create service and bind them to queue
5. Begin the conversation by sending messages.