ASp.Net day

Micro blog



About Satalaj

www.satalaj.com

The best inline translator

Live lookup to see what asp.net developers are searching





Application Pool and Worker process       by Satalaj 10. March 2010 05:13
    

 In IIS 6.0 you can assign 4000000 worker process to server your Application Pool.
To know how many worker processes are presently serving your application pool, you can open command prompt and
execute comman IISapp.Vbs
It will tell information about  W3Wp process  and its process ID.

e.g.

C:\Documents and Settings\Administrator>iisapp

W3WP.exe PID: 30736   AppPoolId: ReportServer

W3WP.exe PID: 12348   AppPoolId: ReportServer


     

asp.net process model       by Satalaj 24. February 2010 07:37
    
We can configure the Application Pool Recycling in two ways.

1. Reactive application pool process recycling.

2. Proactive application pool process recycling.

Reactive Process Recycling:
It happens when process is not functioning properly or unable to serve requests. 
Symptoms: Process deadlocks, access violations, memory leaks, Insufficiant memory and so on, in order to trigger a process recycle.
You can help control the conditions that cause a process restart by using the requestQueueLimit, memoryLimit, and shutdownTimeout configuration attributes.
For more information about these attributes, see the <processModel> Element configuration section of Machine.Config file.

Proactive Process Recycling
Proactive process recycling restarts the worker process periodically even if the process is healthy.
This can be a useful way to prevent denials of service due to conditions the process model is unable to detect.
A process can be restarted after a specific number of requests or after a time-out period has elapsed. You can enable proactive process recycling using the timeout, idleTimeout, and requestLimit configuration attributes. For more information, see the <processModel> Element configuration section of Machine.Config file.

Below are the default settings of Process model found at machine.config file.

<processModel

enable="true"

timeout="Infinite"

idleTimeout="Infinite"

shutdownTimeout="0:00:05"

requestLimit="Infinite"

requestQueueLimit="5000"

restartQueueLimit="10"

memoryLimit="60"

webGarden="false"

cpuMask="0xffffffff"

userName="machine"

password="AutoGenerate"

logLevel="Errors"

clientConnectedCheck="0:00:05"

comAuthenticationLevel="Connect"

comImpersonationLevel="Impersonate"

responseRestartDeadlockInterval="00:09:00"

responseDeadlockInterval="00:03:00"

maxWorkerThreads="20"

maxIoThreads="20"

/>


Satalaj

     

asp.net connection       by Satalaj 15. February 2010 08:02
    

  If your asp.net web application is communicating with third party API for posting or getting information and you encountered with
an error say unable to connect remote server, probable you have reached the max connection that your web application can setup with third party API.
In this scenario you can manually configure your web.config MacConnection settings as shown in below box.

<system.net>
  <connectionManagement>
   <add address="*" maxconnection="1000000" />
  </connectionManagement>
 </system.net>

Read more about client and server communication here
http://www.revenmerchantservices.com/post/2010/01/25/client-server-communication.aspx

Satalaj

      
     

windows server 2003 x64       by Satalaj 4. February 2010 08:29
    

  After doing lots of troubleshooting to install ODBC drivers on windows 2003 OS machine, I found that it was 64 bit where I was trying to
install 32 bit ODBC Drivers.
  well, here is command to know what type of CPU architecture you have.
Open a command prompt and execute systeminfo.exe

C:\>systeminfo.exe

Host Name:                 xxx
OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 3 Build 2600
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:         
Registered Organization:  
Product ID:               
Original Install Date:     11/16/2005, 3:10:01 PM
System Up Time:            0 Days, 3 Hours, 39 Minutes, 28 Seconds
System Manufacturer:       Gigabyte Technology Co., Ltd.
System Model:              945GCMX-S2
System type:               X86-based PC
Processor(s):              1 Processor(s) Installed.


Below are the results for 64 bit machine

C:\Documents and Settings\Administrator>systeminfo.exe

Host Name:                 xxxx-xxxx
OS Name:                   Microsoft(R) Windows(R) Server 2003 Enterprise x64 E
ition
OS Version:                5.2.3790 Service Pack 2 Build 3790
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
Registered Owner:          xxx
Registered Organization:   xxx
Product ID:                
Original Install Date:     4/3/2008, 6:39:26 AM
System Up Time:            0 Days, 3 Hours, 29 Minutes, 11 Seconds
System Manufacturer:       
System Model:              AWRDACPI
System Type:               x64-based PC
Processor(s):              2 Processor(s) Installed.

Systeminfo.exe is very useful command to know your PC configuration and Service pack info etc.

Before downloading any software make sure that you are downloading correct version or edition which supports your CPU architecture.

Satalaj

     

Error: The SSIS Runtime has failed to start the distributed transaction due to error 0x8004D01B "The Transaction Manager is not available.". The DTC transaction failed to start. This could occur because the MSDTC Service is not running.       by Satalaj 2. February 2010 08:52
    


If you are using transaction in SSIS packages, you may encounter with this error.

Quick fix 

Open you .net command prompt type

MSDTC -install

After installing MSDTC, service you need to start it using below command

Net Start MSDTC

well, you can use Net start or Net stop to start and stop an services


Satalaj

 

     

Connection pooling       by Satalaj 29. January 2010 12:16
    
kick it on DotNetKicks.com


  Hi, my name is Satalaj. Here, I'm going to explain what is connection pool with solid proof.
Connection pool as name suggest its a pool of Established connections.
When we are closing the connection in finally or in try catch block that doesn't mean we are closing Established connection with your db server.
Closing connection means notifying the application about that connection is free for future request.

Here, I will tell my connection string to use min pool size = 1 and max pool size = 2.

As soon as pool gets initialized it will establish only one connection with SQL server db.  

You can use below query to test how many connections are established with your MS SQL db server. I established the connection with asptest DB.

select db_name(dbid) as DataBaseName , count(dbid) as

NoOFConnections , loginame as LoginName

from sys.sysprocesses where dbid > 0 and db_name(dbid) = 'apitest'

group by dbid,loginame

 

Here is screen shot of Established connection.

 

 I fired a command netstat -b from my command prompt and found that WindowsApplication1.VShost.exe with process ID 6140
Established one connection with MS SQL server IP 192.168.1.1.28 on port 1433.

My application is running and it has processed his task and I have closed the connection. However, you can see the connection is Established
and it will stay established, still the life of application. If I colse the application, I will not see any connection with my DB APITEST.

   TCP    smartmirror:2096                      192.168.1.28:ms-sql-s  ESTABLISHED     6140
  [WindowsApplication1.vshost.exe]

In my application I have one established connection. What will happen If I get 2 requests simultaniouesly?

Ans. The application will establish another connection to DB server as my Max pool size is 2 and that new connection will serve the request.

What if I get 3 or 4 simultaneous requests?

If there is no free  connection available in connection pool the application will throw an error

Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
 

What happens when I set Min pool size = 10 in my connection string ?
The application will establish 10 connection with DB.

You can see it by using query above and at client / server side, you can execute netstat -a command to know
which are the ports participates in this communication. You can see how my application is talking to sql server using ports ranging from 3979 to 3988.

 TCP    smartmirror:3979       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3980       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3981       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3982       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3983       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3984       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3985       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3986       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3987       192.168.1.28:ms-sql-s  ESTABLISHED
 TCP    smartmirror:3988       192.168.1.28:ms-sql-s  ESTABLISHED

It proves that I have 10 Established connections with SQL server and my application.
when I tell the connection object to close the connection, It only notifies the application about that "free connection", which can be used to serve next request.
When I tell connection object to open a connection I get a free connection form connection pool.


To know more about, how clients talks to the server refer http://revenmerchantservices.com/post/2010/01/25/client-server-communication.aspx

You can have multiple pools in applications. Of Course, there is a limit as there is limits on available ports ranging from 0 to 65535.

Its best practice not to have connection string opened in infinite time to serve the request. If you let the connection opened for infinite loop
your application will not be able to serve other requests. you can try it yourself by setting min and max pool size of your connection string.

By default min pool size is 0 and max pool size is 100.

Conclusion: I told connection object to open a connection with SQL DB server means I'm telling connection object to setup actual connection with DB server? 
                No, I'm telling the connection object to get the already established free connection from connection pool.

I hope you understood the location of Connection Pool and its importance.

Satalaj.

     

client server communication       by Satalaj 25. January 2010 03:47
    
kick it on DotNetKicks.com

  I was wondering to know how two computers can communicate with each other then I came to know its a client and server who are responsible to setup that communication.
Well, client and server both are applications or you can say computer programs.

Server: Its an application which listens on port and serves the request.

Client:  It's also an application who sends a request to server on particular port.

  Lets take an example of web, where browser (IE, FF) are clients who sends the request to server on port 80.
On server, there are multiple applications who listens on particular port, like IIS service listens on port 80 where SQL server listens on port 1433. 
First browser should know the location of server. That's nothing but the IP address of SERVER.
 Only one application can listens on port 80 it can be a IIS or Apache. Both applications can't listens on same port. That's why, if we tell the IIS to
listen on port 80 we need to tell Apache to listen on different port like 8080. So when request came to port 80, IIS will serve that request
and when request came to port 8080 Apache will serve that request.
If we are having two IP addresses assigned to the server then for IP address 192.168.1.1 we can tell the IIS to listen on port 80
and for IP address 192.168.1.2 we can tell Apache to listen on port 80. In this case requests coming to IP 192.168.1.1 port 80 will
get served by IIS and requests coming on 192.168.1.2  port 80 will get served by Apache. This is how we can resolve the conflicts.

   Lets talk about how Client communicates with server.
E.g. 
  Suppose, your IE requests a page http://www.google.com/. It will start establishing the communication with http://www.googe.com/.
During this time if you are trying to request another page of http://www.google.com/ it will establish another connection with server.
In first case, client needs to open a port with server lets say 1001 is opened to communicate with server and this port is engaged.
Means communication is not established yet. As 1001 is engaged second request opens next port 1002 with server and start communicating.
 Server establishes the communication with port 1001 and responds to client on port 1001, for second request it responds to client
on port 1002.
 You can use netstat command from command prompt to see foreign IP address , ports and local IP address, ports.
It also tell us the state of communication whether its established or waiting for server to respond.

 TCP    smartmirror:1455       bom01s01-in-f86.1e100.net:http  CLOSE_WAIT
 TCP    smartmirror:1495       digsby04.rit.edu:5222  ESTABLISHED
 TCP    smartmirror:1497       69.46.36.6:http        ESTABLISHED
 TCP    smartmirror:1501       bom01s01-in-f99.1e100.net:http  ESTABLISHE
 TCP    smartmirror:1502       bom01s01-in-f147.1e100.net:http  ESTABLISH

Here smartmirror is my local IP and 1497 is my local port who established connection with foreign IP 69.46.36.6 on port http (80)

Conclusion:
 When clients talks with server on port, it doesn't mean that clients needs to have port 80 open at his end.
Clients open the available port 1455 at his end and send requests to server on port 80. Server sends a response to client on
client side port 1455.
The detailed list of available port can be see here http://www.iana.org/assignments/port-numbers

There exists 0 to 65535 ports out of these ports, ports ranging from 49152 to 65535 are available for
dynamic or private ports.

I hope you got clear idea of how client communicates with server.

Satalaj
http://www.satalaj.com/

     

C# html Parser       by Satalaj 22. January 2010 10:44
    

  If you came here by searching for C#.net or VB.net html parser, your search ends here.

While developing screen scrapping with C#.net, I came across very rich open source HtmlParser. Who is capable of parsing entire html document.

Here is a link to download and parse the required fields in html  
http://www.codeplex.com/htmlagilitypack.

It is very similar to librarys provided by .net to parse or iterate XMLDocuments.

code snippet:

It will give you list of  all nodes of type Input.  Here str is your actual HTML string that you received in HttpWebResponse object

 HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument();

hd.LoadHtml(str);

HtmlNodeCollection hc = hd.DocumentNode.SelectNodes("//input");


You can use Xpath query to iterate nodes and ChildNodes.

Satalaj

     

screen scrapping asp.net pages       by Satalaj 22. January 2010 10:19
    

  If you want to crawl asp.net pages using HttpWebRequest and HttpWebResponse, you need to POST the __VIEWSTATE, EVENTARGUMENT and EVENTTARGET
along with your Request. 
  If that page stores session or cookies you need to pass session cookies and Cookies along with the HttpWebRequest object.
You need to use Post Method.

 your post data will look like this

string postData = "__EVENTARGUMENT=" + value + "&_EVENTTARGET="+ targetValue+ "&__VIEWSTATE="+ViewState ;

You first use tools like fiddler to know how your broser post the data to .aspx pages then prepare your post string to post the data.


Satalaj

     

Server.Transfer vs Response.Redirect       by Satalaj 21. January 2010 10:50
    

 Use Server.Transfer. whereever it is possible, use the Server.Transfer method instead of the Response.Redirect method.
Response.Redirect sends a response header to the client that causes the client to send a new request to the redirected server by using the new URL.
If you have tools installed like fiddler you can easily see what has been posted back inside Header to the clients like IE.
Its a Status code 302 and header contains location of resource.

 Server.Transfer avoids this level of redirection by simply making a server-side call.
You cannot always just replace Response.Redirect calls with Server.Transfer calls because Server.Transfer uses a new handler during the handler phase of request processing.
If you need authentication and authorization checks during redirection, use Response.Redirect instead of Server.Transfer because the two mechanisms are not equivalent and
as you know during authontication we check wheather cookie exists in Request or not. There we must use Response.Redirect.

When you use Response.Redirect, ensure you use the overloaded method that accepts a Boolean second parameter, and pass a value of false to ensure an internal exception is not raised.

You can see that exception by simply putting Try catch Blocks in your application. To avoid internal exception pass second parameter as false.

Also note that you can only use Server.Transfer to transfer control to pages in the same application. To transfer to pages in other applications, you must use Response.Redirect.

That means you can't call the pges residing outside of your application domain. like
http://bing.com  http://google.com www.asp.net can't put inside your server.transfer method.

Satalaj