ASp.Net day

Micro blog



About Satalaj

www.satalaj.com

The best inline translator

Live lookup to see what asp.net developers are searching





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

     

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.

     

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

     

HTTP Error 404 - File or directory not found.       by Satalaj 19. January 2010 05:09
    

  Scenario, you installed the IIS 6.0 and framework 2.0 on windows 2003 operating system. After deploying the web you observed that web is
responding an error with 404.
  By default, once you installed the IIS. It want not allow to run ASP.net or web pages or CGI, perl etc.
you need to allow them to fix this error. You need to open IIS 6.0 and find the node called Web services extensions.
In right pen you can allow or prohibit the access to ASP.net 2.0 or CGI.
For more information you can refer below link
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/44f16c37-f727-4244-9813-2289e13dadba.mspx?mfr=true

or you can use support forum at www.iis.net

The default IIS settings will allow you to only see the Static pages.




Satalaj

     

cliconfg       by Satalaj 6. January 2010 05:34
    

Scenario:
  Suppose you are having two server SERVER A  (web application server) and SERVER B (SQL database server).
Your client wants to use upgraded Machine for SQL server (SERVER C). First you need to restore the databases from Sql server B to SQL server C.
Web application Server A contains 1000+ web sites, who are using SERVER B database. Imagine, how many web.config files you would be required to update
and applications whose connection strings not stored in web.config.

Here is how quickly we can make system live using SQL server nework utility.

MS SQL SERVER  CLICONFG

Using Sql server network utility we can route the traffic to new sql server without changing
any application configuration.


Go to your web application Server A and follow below commands.

Fig.1.

It will open SQL server client network utility.

Fig.2.

Click on add then click on TCP/IP

e.g.

All applications are accessing SQL server using IP 192.168.1.1.
Now, let’s say it is changed to 192.168.1.2.

Below fig shows how to configure application server to use new IP, instead of doing changes in all web.config / App.config or any hard coded IP.

Fig.3.

If applications are accessing SQL using domain or name of sql server. use Named Pipes.

Here you can see, you are not only just be able to route the traffic to IP but also to ports,
This is very useful utility.

     

favicon ie       by Satalaj 5. January 2010 08:33
    

What is favicon? and How can I use it?
  Its an image displayed next to your Address bar of browser. you can refer http://en.wikipedia.org/wiki/Favicon
Many times developers are complaining, image is getting displayed properly in Mozila but not in IE.
To get it displayed in IE you need to do proper formatting of image, Mozila is capable of rendering all types of images.
you can also use animated images.

   If you are facing any problem, I would like to suggest use online favicon generator http://www.html-kit.com/favicon.
You can put the favicon.ico in the root folder of your application.

Here is HTML syntax that you need to add in your Head scetion of Page.

  • <link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico">
  • <link rel="icon" type="image/png" href="http://example.com/image.png">
  • <link rel="icon" type="image/gif" href="http://example.com/image.gif">
  •           Additionally, such icon files should be either 16×16 or 32×32 pixels in size, and either 8-bit or 24-bit in color depth (note that GIF files have a limited, 256 color palette entries). Firefox can display animated GIFs
              and (starting with version 3) APNGs as icons.

     

         

    JavaScript inside Div panel       by Satalaj 16. December 2009 06:20
        

       I added Javascript inside div panel and Made that div hidden. I was expecting it will not request the JavaScript from server.
    I was wrong, It request the scripts even if the parent container is hidden. I used tool called Fiddler to monitor the Http request.
    Fiddler can be downloded from here
    http://www.fiddler2.com/Fiddler2/version.asp . Its nice tool to know how browser is requesting the server.
    Its nice tool to debug at cleint side.

    e.g.

     <div>
     
        <script src=
    http://some_domain.com/some_java_script.js >

        </script>
     
    <div>

    There are so many tools available to monitor http / https request like Http Viewer
    http://www.httpwatch.com/?gclid=CKq12MrF2p4CFYIvpAodJQ4uIw


    Satalaj

         

    The trust relationship between this workstation and the primary domain failed       by Satalaj 15. December 2009 08:19
        


    The trust relationship between this workstation and the primary domain failed.


    Quick fix

    Log on locally as a local administrator. In the Network tool of Control Panel, select Change and enter a Workgroup name, leaving the domain. Restart the computer and log on locally as a local administrator.

    There are two methods to rejoin the domain:

    • You can join the domain from the client if at the same time you can provide an administrator username and password on the domain.

      -or-
    • You can delete the existing computer account in Server Manager, recreate the computer account, synchronize the domain, and then on the client rejoin the domain.


       

    The trust relationship between this workstation and the primary domain failed.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.SystemException: The trust relationship between this workstation and the primary domain failed.


    Source Error:


    You can also refer
    http://support.microsoft.com/default.aspx/kb/162797


    Satalaj
         

    tooltip asp net       by Satalaj 11. October 2009 11:07
        
    All ASP.net controls who get rendered at client side has tooltip property

    e.g. 
      <asp:Label ID="Label1" ToolTip="This is test lable tool tip " runat="server" Text="Label"></asp:Label
    >

    <asp:TextBox ID="TextBox1" ToolTip="This is test TextBox tool tip " runat="server" ></asp:TextBox>


    You can create Baloon tooltip like this http://www.asp.net/community/control-gallery/Item.aspx?i=2037

     try it live http://www.aspnettooltip.com/aspnettooltip_Demonstration.aspx

     

         

    Do you want to view only the webpage content that was delivered securely       by Satalaj 30. September 2009 08:25
        


    If your page is requestiong data from Insecure zone http:// you will see below warning. 

    "  Do you want to view only the webpage content that was delivered securely "

    Those data can be from Script, images or Iframe.

    If you are accesing web using Https:// make sure, all requests requested by your page are coming from Https:// and not from http://.