Sunday, May 11, 2008

Very Simple AJAX Example

Below is a very very simple AJAX example. This is intended for AJAX starters and is not for people who already know about AJAX.

Overview
AJAX - Asynchronous Java and XML has been the buzzword for the last couple of years. Though it is being used for a very long time now, the term AJAX was coined recently. AJAX is an attempt to give the web user an interactive, quick and rich user experience while navigating through your web application. Normally while requesting pages, every request causes a roundtrip to the server causing the page to freeze and prevents the user from doing any kind of interaction with the page. AJAX moves away from this feature where the user can continue working with the page while requests to the server happen in the background. A very good example of this is Google Maps.

The communication with the server is accomplished using XmlHttpRequest object. This object is responsible for opening the connection to the server and sending the request. Once request is complete and data is recieved, the page elements can be modified/updated as needed.
In the below example, when you hover over the label, the sendRequest method gets called which is responsible for opening the connection and sending the request to the "AjaxResponse.html" page on the server. This page just outputs the text "Hello World". The client callback function (callBackFunction()) gets triggered everytime the request state changes and raises an alert once the callback is complete.


   1:  <html xmlns="http://www.w3.org/1999/xhtml">
   2:      <head>       
   3:          <title>Basic AJAX Example</title>  
   4:          <script type="text/javascript">                
   5:          var xmlHTTP = null;        
   6:          //This method gets called everytime the request state changes
   7:          function callBackFunction()
   8:          {   
   9:              //check to see if the status of the request has changed
  10:              //other states are 0 = created but not initialized (open method not yet called),
  11:              //                 1 = initialized (sent method not yet called), 
  12:              //                 2 = sent request (response text and response body not available), 
  13:              //                 3 = recieved request (response text and response body not available),
  14:              //                 4 = all data has been recieved (response text and response body available)
  15:                  if(xmlHTTP.readyState == 4)
  16:                  {
  17:                      //check to see if the status is ok
  18:                      if(xmlHTTP.status == 200)
  19:                      {
  20:                          alert('call back completed and data is recieved from the server');                    
  21:                      }
  22:                  }
  23:          }
  24:      
  25:          //This method creates the xmlHTTPRequest object and sends the request
  26:          function sendRequest()
  27:          {
  28:              //check the browser and instantiate the appropriate object -- IE 7, Mozilla
  29:                  if(window.XMLHttpRequest)
  30:                  {       
  31:                      xmlHTTP = new XMLHttpRequest();
  32:                  }
  33:              //Previous versions of IE like IE 5 and old browsers
  34:                  else if(window.ActiveXObject)
  35:                  {
  36:                      xmlHTTP = new ActiveXObject(Microsoft.XMLHTTP);                    
  37:                      //alernative 
  38:                      //xmlHTTP = new ActiveXObject(MSXML2.XMLHTTP);                                
  39:                  }
  40:                  else
  41:                  {
  42:                      alert('Browser not supported');
  43:                  }                      
  44:              //open a connection using a xmlHttpRequest object
  45:                  xmlHTTP.open("GET","AjaxResponse.html", true);
  46:              
  47:              //set the method to be called when the request status changes
  48:                  xmlHTTP.onreadystatechange  = callBackFunction;
  49:              
  50:              //send the request
  51:                  xmlHTTP.send(null);            
  52:          }
  53:      </script>    
  54:      </head>    
  55:      <body>
  56:              <label id="label1" onmouseover="sendRequest();">Hover over me</label>
  57:      </body>
  58:  </html>
Again, this is a very simple example and you should be able to find more advanced and complicated examples on the web. The page elements can be modified using javascript to insert the response text on the calling page.
 

Sunday, May 4, 2008

MOSS Search error

Scenario: Multiple web front ends with MOSS search service(both query and index) running on one of them.Everything is fine on the web server which also host the moss search service. Specifically, search queries work fine without any errors.

Issue: The other WFE's(not hosting the search service) throw errors when trying to sort the search results. I repeat, the WFE's throw errors only when trying to sort the results. Otherwise they work fine. I can still do search on these servers, but when trying to sort the search bombs out.

The error message thrown is:

The specified network name is no longer available. (Exception from HResult: 080070040

The event view shows the following message (or something simillar):
The last query machine was taken out of rotation. Propagation may be neccessary. The query machine will be retried in 15 seconds again.
The uls logs show the following message :


0x80070040000000006B49C6F8d:\office\source\search\ytrip\tripoli\common\crequest.cxx246

0x80070040000000006B49C6F8d:\office\source\search\ytrip\tripoli\common\crequest.cxx246 _LokRelegateMachine just relegated the last query machine! - File:d:\office\source\search\ytrip\tripoli\icommand\qpcache.cxx,Line:1393

0xc000020c000000006B49C73Ad:\office\source\search\ytrip\tripoli\common\crequest.cxx244 In CRootQuerySpec::Execute - caught exception: 0x80070040, translated to: 0x80070040 - File:d:\office\source\search\ytrip\tripoli\icommand\qryspec.cxx,Line:767
Log Query: More Information: The specified network name is no longer available.

The same code gets executed on all the WFE's but the error does not happen on the WFE running the query service. Assuming there is an issue with the firewall, how does the search work on these WFE's (when no sorting is done) ? I have been trying to fix this error for sometime now, but didn't get enough time to research more. I will keep looking for more information on this error and post a resolution if I find one.

Monday, March 24, 2008

Who is a SharePoint Developer and What is SharePoint ?

I recently had a conversion with one of my developer friend (Dilbert) which was something like this:

Prashanth: Hey Dilbert! How r u?

Dilbert: I am fine Prashanth. How r u doing?

Prashanth: Never been so great. So what r u working on these days?

Dilbert: I have been developing .NET applications. What’s up with you?

Prashanth: I am working on SharePoint. I build and maintain SharePoint applications.

Dilbert: So you basically take care of document libraries. I heard that that SharePoint is a document repository.

Prashanth (fuming with rage...): I do little more than that and SharePoint is a LOT more than a document repository. It is one of the many, many features provided by SharePoint.

Dilbert: Oh is it? All this time, I was thinking of SharePoint as a SourceSafe. BTW, Do you get to work on .NET applications?

Prashanth(trying to control himself to not hit Dilbert...): SharePoint is built on the .NET platform. Microsoft Office Server 2007 is built on ASP.NET 2.0 and you can basically do whatever you do when developing your .NET applications. SharePoint provides you with a lot of click-create websites based on templates, which may otherwise take days to build. As a developer, SharePoint provides you a great object model which enables you do anything that can be done by the wizards/user interface. This helps in developing rich business applications.

Dilbert: So you basically create websites with a click. Where is the development then?

Prashanth: It’s true that most of the times, I use the built-in wizards to create the sites. But, lot of customizations also needs to be done depending on the business requirements. It involves developing web parts, master pages, user controls and basically everything a normal ASP.NET developer does. It also involves using XML to create/modify site definitions and site templates which is a major part of SharePoint Development. SharePoint provides tight integration with InfoPath and Excel services providing you with a great development environment. Just imagine the kind of development you can do with these tightly-coupled technologies !

Dilbert: What else is part of SharePoint?

Prashanth: SharePoint has a lot more features aimed at Collaboration, Business Intelligence, Content Management, Search for improving Productivity, Communication and for finding information very easily. To summarize:

  • Provides a simple, familiar, and consistent user experience -By tightly integrating with familiar client desktop applications, e-mail, and Web browsers
  • Boosts employee productivity by simplifying everyday business activities - By providing out-of-the-box workflows for initiating, tracking, and reporting common business activities such as document review and approval, issue tracking, and signature collection
  • Helps meet regulatory requirements through comprehensive control over content - By specifying security settings, storage policies, auditing policies, and expiration actions for business records
  • Effectively manage and re-purpose content to gain increased business value - By being able to submit documents for approvals and schedule deployments for intranet and internet
  • Simplifies organization-wide access to both structured and unstructured information across disparate systems - By giving users access to line of business data like SAP, Siebel and many other disparate content sources
  • Connects people with information and expertise -By providing enterprise search which is capable of returning back web pages, people information and documents
  • Accelerates shared business processes across organizational boundaries - By providing great smart electronic forms out of the box
  • Helps in sharing business data without divulging sensitive information
  • Provides a single, integrated platform to manage intranet, extranet, and Internet applications across the enterprise
Though I am not a SharePoint eulogist,working on it for sometime now has given me a better understanding and also the made me understand the essence of it. I hope Dilbert has a better understanding of it now.

Thursday, March 20, 2008

MCTS (70-630) - Configuring WSS 3.0

I recently took the 70-630 exam and passed. There were questions on Load Balancing like using unicast/multicast modes and a few other network related questions. I still have two more exams to take in the Office Sharepoint Server 2007 section and Iam looking forward to take them soon.....

Saturday, March 1, 2008

Attempted to read and write protected memory. This is often an indication that other memory is corrupt.

Wasn't MOSS 2007 sp1 supposed to fix this problem ? I have the MOSS 2007 sp1 installed on a 64 bit machine but still, one of the WFE throws this error. The actual server hosting the central admin is fine and does not show any indication of this error message. In case you come across the same error message, the workaround is to restart the spadmin service (WSS Admin Service) . Few of the searches on internet do refer to the Timer service, but for me restarting the admin service fixes the problem temporarily. Use the task scheduler to schedule a restart (NET Stop SPAdmin, NET Start SPAdmin) whenever event 6398 occurs.

Thursday, February 28, 2008

The protocol handler cannot be found. Check that the handler has been installed.

After restoring databases from the production servers, I started a crawl. Instead of seeing "Green Messages", I just saw one error message:
The protocol handler cannot be found. Check that the handler has been installed.
I usually restore databases on the dev machine without using the preparetomove command. But today, I was really into the right mood and wanted to follow all the rules religiously. So, before detaching the database, I ran the following command:
stsadm -o preparetomove -contentdb sqlserver:dbname -site http://mymosssite
Then I detached the database using the Central Admin and started the database restoration process. Once done, I added the content database back. I was really happy that everything went smooth without any issues. It was now time to crawl the site and there for I started a full crawl on my site.But as mentioned before the crawl bombed out with the above error message. I went into the eventviewer and saw the following error messages:
The update cannot be started because the content sources cannot be accessed. Fix the errors and try the update again.
The protocol handler cannot be found. Check that the handler has been installed. (0x80040d1a)
I did not understand what was happening and so I started thinking about the changes I made. Before restoring the databases, I stopped the wss help search as I was not using it. Also, I was more inclined towards the sync between the content databases and the ssp. So, I took the following steps expecting to fix the issue:
  • Restarted the wss help search

  • Restarted the office search - net stop osearch

  • Ran the command: stsadm -o synch -deleteolddatabases 0
After this, I started the crawl again and now it worked ! Though I do not know exactly, which of the above steps fixed my issue, I am delighted that it was working again. If anyone knows the exact reason for this issue, please let me know.
Also, if you see the error "Error in the Site Data Web Service. (Specified argument was out of the range of valid values. Parameter name: databaseId)", run the synch -deleteolddatabases command and it should fix the error.

Sunday, February 24, 2008

Output cache not used. Reason: User can view an unpublished version of the current page

I was trying to enable output caching on an authenticated MOSS site and followed the below steps:

  • Site Actions -> Modify Site Settings -> Modify All Site Settings
  • Site Collection Administration -> Site Collection Output Cache
  • In here, I enabled the cache profile, disabled anonymous cache profile, set the authenticated cache profile to Extranet(Published Site)
  • I also enabled the "Enable debug cache information on Pages" to check if the caching was working as expected
  • Now, I logged in as the site administrator and checked the html source of the page. Instead of seeing the following message: "Rendered using cache profile:Extranet (Published Site) at: 2008- 02-24T10:08:03", this message came up : "8 Output cache not used. Reason: User can view an unpublished version of the current page".
  • The above was expected because, I was logged in as a site collection administrator. I logged off and logged in as a different user(reader access) and still was seeing the same message : "8 Output cache not used. Reason: User can view an unpublished version of the current page. "
  • I tried using different user id's but was still the same error message.
  • So, I went back to the site collection output cache profiles page and modified the Extranet(Published Site) property as shown below:

  • After this is done, I logged in as a reader and behold ! It works as expected spitting out a cached version of the page.
  • But the downside to the above setting is that the writers will be seeing a cached version of the page. I still need to figure out why the readers were able to see a unpublished version of the page.