Thursday, July 18, 2013

Difference between asynchronous (AJAX) and synchronous request?

Now-a-days, this is a very common question that been asked in all most every basic interview – What is the main strength of AJAX? Or why and when should we use AJAX in web application?
And the most common answer is – “AJAX does not refresh or reload the whole page”.
But, the more perfect answer is – “AJAX is an asynchronous technology where others request are synchronous.”
So, what is the difference?
In a word, a program does not wait for response after requesting an asynchronous call whereas synchronous does so.
Here is a simple example –
function check() {
var a=0;
a = getStatus(“getstatus.php?id=5”);
if(a==1) {
} else {
alert(“not active”);
Here getStatus() function sends a AJAX request to the server with “getstatus.php?id=5” url and the php file decides (from database may be) the status and output/response as 1 or 0.
But, this function will not work properly. It will alert “not active” instead of “active”. And yes, that is for the asynchronous request.
The reason is – when a = getStatus(“getstatus.php?id=5”); line is being executed program does not wait for the response of setStatus() function. So, value of keep unchanged or set to null.
So, how should we work with asynchronous request?
Of course, using callback function. Callback function is that function which is triggered when the request completes to get the response (or as defined).

Refer link:- 

Monday, July 15, 2013

Read /Write in XML column in sqlserver

This is simple example to read and write in xml column of a table in sqlserver . You can directly execute in sqlserver too.

----------------- To insert/update in xml column
declare @t table (id int, xmlCol xml)

insert into @t values(1,'14747')

select * from @t;

update @t set xmlcol = '1474714749' where id =1

select * from @t

--even you cast as
select cast ( xmlcol as varchar(max)) , * from @t

----------------- Select example-----1st example --
Declare @responce xml; DECLARE @douvalue varchar(100);
SELECT @responce = ' 60.4655'
select @douvalue = @responce.value('(/double)[1]', 'varchar(100)');
select @responce, @douvalue AS DownloadEnvironment

--Declare @responce xml;
SELECT @responce = '

;WITH XMLNAMESPACES(DEFAULT 'http://www.webserviceX.NET/')
select @douvalue = @responce.value('/double[1]', 'varchar(100)');

select @douvalue

------2nd example - To retrieve value ---
declare @xml xml 
set @xml = '14747  14749  14750  14752'
        xmlnodes.idnode.value('.', 'int')
        @xml.nodes('/root/id') as xmlnodes(idnode) 

--3rd example    -- even you compare with other table too -----
        a.activityID, a.columnName,
        convert(varchar(12), a.createdDate,13) as createdDate ,
        CONVERT(varchar(15),CAST(a.createdDate AS TIME), 100) as activityTime     
        @xml.nodes('/root/id') as xmlnodes(idnode) 
        JOIN Activity a 
            ON   xmlnodes.idnode.value('.', 'int') = a.activityID 
   WHERE = '1' AND
        (a.activityType = 'Viewed' OR a.activityType = 'Edited')  
        a.createdDate desc,
        a.activityTime desc

Friday, July 12, 2013

Read And write xml data in xml column in sqlserver

Suppose I have an entry

assetsIDs_xml  '119'

update Designs set assetsIDs_xml = ''
where ( assetsIDs_xml.exist('/root/id[text()=119]') =1 ) 

            tableName c
            AND ((c.userIDs_xml.exist('/root/id[text()=sql:variable("@userID")]') = 1)  

Monday, July 1, 2013

IIS not work, Give error "HRESULT...." or When IIS start gives error "Already running a process on this port"

Hello All,

In my pc, IIS was working fine as I know. Today when I want to run my site from IIS. It gives me above error . I am searching lot for my this issue. Even I was did stop my firewall , still getting the same.

So I googling and get solution that skype is also share the same port of IIS : 80. So follow below to solve this issue.

The cmd NETSTAT -ano showed Skype (via the PID) was using port 80.
This was preventing IIS starting a local website with the message:
The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
This was resolved in Skype by unchecking Tools > Options... > Advanced > Connection > "Use port 80 and 443 as alternatives for incoming connections"

Refer link :Prevent Skype using port 80 and causing IIS to throw a HRESULT: 0x80070020 Exception