ms sql function return table and call the return table

29. November 2009

create function t_sql_tvfPoints()
returns @points table (x float, y float)
as begin
insert @points values(1,2);

return;
end



SELECT * from dbo.T_SQL_TVFPOINTS()

 

posted by Aamir Hasan

092-333-5494532


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, SQL 2005 & 2008

DDL LOG TRIGGER MS SQL 2005 AND 2008

29. November 2009


CREATE TRIGGER [DDLLOGTRIGGER]
ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
AS

SET NOCOUNT ON

DECLARE @DATA XML
SET @DATA = EVENTDATA()

insert into TRACK_DL(databasename, eventtype,
objectname, objecttype, sqlcommand, loginname,HOSTNAME,APPNAME)
values(
@data.value('(/EVENT_INSTANCE/DatabaseName)[1]', 'varchar(256)'),
@data.value('(/EVENT_INSTANCE/EventType)[1]', 'varchar(50)'),
@data.value('(/EVENT_INSTANCE/ObjectName)[1]', 'varchar(256)'),
@data.value('(/EVENT_INSTANCE/ObjectType)[1]', 'varchar(25)'),
@data.value('(/EVENT_INSTANCE/TSQLCommand)[1]', 'varchar(max)'),
@data.value('(/EVENT_INSTANCE/LoginName)[1]', 'varchar(256)'),

APP_NAME() ,

HOST_NAME()

)

--DISABLE TRIGGER DDLLOGTRIGGERON DATABASE
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ENABLE TRIGGER [DDLLOGTRIGGER] ON DATABASE


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, SQL 2005 & 2008

ASP.NET 2.0 and AJAX (Asynchronous JavaScript and XML) Callback working process

26. November 2009

AJAX includes:

  • Presentation content using XHTML and CSS
  • Dynamic display and interaction with XHTML (DHTML) using the Document Object Model (DOM)
  • Data interchange using strings, often in XML format 
  • Asynchronous data retrieval using an http request object 
  • JavaScript - to bind everything together 

Client callbacks can be synchronous or asynchronous.   the browser creates a new connection to send the callback to a remote server,   The contents of the entire page do not need to be submitted, so the page lifecycle for a callback skips events associated with rendering page contents on the server.   In addition, sending an asynchronous callback to a server permits an end user to continue working in the client application while the request is processed.  When the response is returned, the appropriate content in the Web page is updated without refreshing the entire page.  shown in below images




Synchronous                                                                  

        


Asynchronous

         

 The diagram below illustrates the difference between the page lifecycle sequence of events between a synchronous page postback and a client callback.  The Page.IsPostback property will return true for both request types.  The Page.IsCallback property will return true only when the request is a client callback.



 
   posted by Aamir Hasan

phone no:092 333 5494532 


 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, Architecture, asp.net, asp.net 4.0

asp.net Callback technique using csharp

26. November 2009

Callback is Light weight tasks Communication with server.Some times we need call server side methods asynchronously without postback. some times we have to post full page postback or partial page postback.now microsoft team have provide the function ICallback using this so easy.

Two example explained down

1) Javascript Serialization  rendering

2) JSON control rendering 

ICallback

ICallback is lightweight process. It uses well known XMLHTTP object internally to call server side method. It does not cause page postback and does not cause page rendering. If we are to show output at the client side, we need to make output HTML ourselves and render the controls manually.

ICallbackEventHandler

ICallback is implemented in ASP.NET by using ICallbackEventHandler interface. It has two methods; one of them is used to call from JavaScript (client side code) and other one returns the result asynchronously back to the JavaScript function.

We just need to perform some action through server side code at server side. It then needs to return the results, but results are in instance or object of any class which would not be easy for JavaScript code to handle. Here we prefer JSON which stands for JavaScript Object Notation.

JSON

JSON is a lightweight, data-interchange format. ASP.NET gives good support for JSON as well. It is rapidly adopting because it is easy read by human and machine as well.

 

ICallback Server Side Implementation

Let us first implement ICallbackEventHandler to call the server side method asynchronously step-by-step

Implement Server Side (C#) Page/Control class by System.Web.UI.ICallbackEventHandler.

The following are the definition of two methods which we need to implement.

RaiseCallbackEvent method invoke through JavaScript function.

public void RaiseCallbackEvent(string eventArgument)

{

//to do code here

}

GetCallbackResult method invokes itself when the processing of RaiseCallbackEvent method is completed.

public string GetCallbackResult()

{

return "";

}

In Page_Load or Page_Init event the following statements are used to register client side methods.

CallServer(arg, context), as the name implies, would use call/raise server side method which was RaiseCallbackEvent string eventArgument).

ReceiveServerData(arg, context) would get the result through arg parameter by GetCallbackResult().

protected void Page_Load(object sender, EventArgs e)

{

ClientScriptManager scriptMgr = Page.ClientScript;

String cbReference = scriptMgr.GetCallbackEventReference(this, "arg",

"ReceiveServerData", "");

String callbackScript = "function CallServer(arg, context) {" + cbReference + "; }";

cm.RegisterClientScriptBlock(this.GetType(),"CallServer", callbackScript, true);

}

ICallback Client Side Implementation

<script language=javascript type=text/javascript>

function ReceiveServerData(arg, context)

{

alert(arg); //just to show output

}

function CallSrv()

{

CallServer('get customer', '');

}

</script>

<input type="button" value="get customer" onclick="CallSrv()" />

That is it. These are the steps which you need to use to call and get results from the server side code using ICallback.

JSON based JavaScript serialization to return results in JavaScript's easily parseable format.

 object we need to return to JavaScript function through JavaScript serialization.

Sample Class:

public class Customer

{

public string Name;

public int Age;

}

JSON Code

Declare string jsonResult at the class level, which would be used to contain final results and returns.

After some sample code in both methods, the code will look like the following:

public void RaiseCallbackEvent(string eventArgument)

{

//populate Customer object to return

Customer customer = new Customer();

  customer.Name = "Aamir Hasan";

  customer.Age = 20;

//javascript serialization of Customer object

System.Web.Script.Serialization.JavaScriptSerializer jss;

jss = new System.Web.Script.Serialization.JavaScriptSerializer();



//stringbuilder to contain serialized customer object

  System.Text.StringBuilder bCustomer = new System.Text.StringBuilder();

  jss.Serialize(customer, bCustomer);



  jsonResult = bCustomer.ToString();

}



public string GetCallbackResult()

{

return jsonResult;

}
 
Asynchronously output would be within a millisecond and without Postback.

 

Callback is a lightweight technique used to call server side methods asynchronously from JavaScript without any postback and reloading/rendering of unnecessary parts of page and unnecessary code.So we can use that when we need to perform any operation at backend means at server, like update records in database, etc. You do not need to send all your contents of page in request and make that object heavyweight which could cause slow performance. 

JSON is lightweight, data-interchange format to make server side class objects easily parseable by client side code to show output on a browser. I used JavaScript serialization technique to convert server side entity into client side entity to make it accessible/readable/useable at client side.

 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, asp.net 4.0

c#3.0, 3.5 new features

26. November 2009

Microsoft reduce the line of code for  developer's.

There are many features, one of them is Auto implemented property. Anonymous types, Partial methods, object initializes, implicitly typed local variables.

Auto Implemented Property

In this we set and get the value in older version of framework we have to sign the variable to temp variable.

[Access-modifier] data type [Name of the property]
{
get;
set;
}

 

In previous version we have done like this.

private
string _FirstName;
public string FirstName
{
    get
    {
        return _FirstName;
    }
    set
    {
        _FirstName = value;
    }
}

2. Implicit Typed local variable

The new data type introduced in the C# 3.5. Normally when you store the elements in the string with the integer value we need to do the type casting. The variable that will be declared with the var keyword and it will be inferred by the compiler at the time of execution.

var
Total = 50 + 50;
var iTotal = 50 + 52.5;
var Name = "Aamir" + "Hasan";
var Name = "Aamir Hasan" + 50;

 

Here what happens when you declare the  var Total = 10 + 10, it will do the addition.

On the other hand, when we declare this variable in the string what happens? Let's see

string
name = 10 + 10;

The result will be 1010. Because it will do the concatenation, until unless do the type casting. Here the expression will be inferred by the compiler.

It can be used to create the array in the similar way.

There are some restrictions to use this feature.

  • We cannot do the increment and decrement operation like i++ or ++i
  • We cannot declare the NULL value to the var variable.
  • It use be declare and initialize on the same statement in the local scope.
  • We cannot initialize the multiple var variables like others. Int  I, j, k;

An anonymous type is one of the new features introduced in the C# 3.0 version. It is a read only property and can be used to assign the set of names constants with the values. These values cannot be changed the outside Anonymous type.

var
Names = new
{
    FirstName = "Senthil",
    LastName = "Kumar",
    Age = "27"
};

It can be accessed with the following:

string
_FirstName = Names.FirstName;

Normally when we define in the enum, there we cannot assign any values.

It will take the order from 0 and will be incremented by one for the every constants in the enum list.

Here the value can be assigned.


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, CSharp



User Name: Guest

Your Ip: 38.107.191.93
Time: