Sunday, March 1, 2009

Loading External Javascript Files

Static:
<script src="/includes/scripts/test.js" type="text/javascript"></script>

Dynamically Static Way:
<script type="text/javascript">
function staticLoadScript(url)
{
document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
}
staticLoadScript("/includes/scripts/test.js");
</script>

Dynamically DHTML Way:
<script type="text/javascript">
function dhtmlLoadScript(url)
{
var e = document.createElement("script");
e.src = url;
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}
onload = function()
{
dhtmlLoadScript("/includes/scripts/test.js");
}
</script>

Reference: http://www.ecma-international.org/publications/standards/Ecma-262.htm

Javascript include from ASP.NET server control

In ASP.NET 2.0 the Page object has a Header property - which contains a Controls collection. This is good news since it makes it possible to (easily) inject a <script type="text/javascript" src="whatever"> into the <head></head> section of the resulting HTML page.

You can - for example from the code of your custom server control - add a htmlgeneric control to the containing page header control like this:

string sInclude = "~/specialincludes/blabla.js";
sInclude = ResolveUrl( sInclude );
HtmlGenericControl Include = new HtmlGenericControl("script");
Include.Attributes.Add("type", "text/javascript");
Include.Attributes.Add("src", sInclude);
this.Page.Header.Controls.Add(Include);
and that would make the resulting html code look like this:

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="/thesite/specialincludes/blabla.js">
</script>
<head>

Track SQL Dependencies

--PAYROLL.dbo.PAY_GETPAYLIST dependents on

EXEC sp_depends @objname = N'PAY_GETPAYLIST' ;

--dependent on PAYROLL.dbo.PAY_GETPAYLIST

EXEC sp_MSdependencies N'dbo.PAY_GETPAYLIST', null, 1315327

--PAYROLL.dbo.PAY_GETPAYLIST dependents on

--oType =1 (Scalar Function), oType =8 (Table)

EXEC sp_MSdependencies N'dbo.PAY_GETPAYLIST', null, 1053183

-- SYS COMMENTS

SELECT distinct so.name

FROM syscomments sc

INNER JOIN sysobjects so ON sc.id = so.id

WHERE charindex('PAY_GETPAYLIST', text) > 0

--INFORMATION_SCHEMA.ROUTINES

SELECT routine_name, routine_type

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_DEFINITION LIKE '%PAY_GETPAYLIST%'

IIS Worker Process and Application Pooling

Web server?
IIS (Internet Information Service) running on a software port like 80 for Http and 443 for Https or any other port set bt the administrator, it can host more than one web site and each web site can hold more than one web application. Web server provides application pooling and hanldes all web request from the internet and forward it to respective web site's application pool for processing and response. IIS can host classic asp applications, asp.net applications, php applications, etc.

Application Pooling?
The Windows IIS web server, has application pools where different web applications or web sites can be pooled. When we say pooled it means it is loaded in the process, so the web requests are processed. Why pooling? becuase the application will handle multiple web requests, the application is loaded once, and remains in the pool for quite some time to process subsequent requests and when remains idel for too long it is unloded. The pooling helps better manage server resources, so the CPU and Memory is not consumed uselessly. An application pool can hold more than one web application, and IIS can have more than one application pools. Application pools it self is comprehensive topic and it provides many things to tune your web application performace.

Worker Process?
As we discussed above, application pooling is done in IIS, Worker Process is actually a program that executes in the system memory for a specific application pool, if we have three application pools and the pools are active than we will have three process running it the system memory, these are the processes which handle the requests and send response. The "w3wp.exe" program can be easily found in the task manager, this is the program running behind the application pool.
We can define more than one worker process in an application pool, by default we have one worker process in an application pool, this means there is only one queue for my web requests, so ten request will execute one at a time.
If i increase the number to 2, so now my application pool has 2 worker process, this means there are two queues for my web requests, so ten request will execute two at a time. Ofcourse the CPU time will be divied between the two worker processes, this means to many worker processes will cut down the overall response time if i have a moderate server, therefore it depends upon the hardware of the server that how many worker processes it can hold.