Saturday, January 12, 2008

SQL Error while using WebParts

"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

The webpart requires the sqlserver 2005 for its working. The webpartmanager is looking for SQL Express 2005 which, by default, is the personalization provider. Now if you remove the SQL server Express 2005 and instead install SQL Server 2005 then vs2005 is not able to find out the location of sql server and throws an error regarding SQL server 2005.
The following steps will help in removing this error

1. Open the visual studio command prompt and type aspnet_regsql.exe. This will open up a wizard to set the SQL server settings

2. Click next next till you click finish in the wizard. This will create a default database aspnetdb in the SQL Server 2005

3.Open the SQL server management and check the name of the server: In my case it is INHCJITBZR1SL. This is actually same as the computername.















4. Open the web.config file. Add the following lines.

<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="SERVER=INHCJTBZR1SL;Integrated Security=true;Initial Catalog=aspnetdb" providerName="System.Data.SqlClient"/>
</connectionStrings>

<remove> will remove the old settings about the sql server.
Basically you are trying to tell .NET where to find teh SQL server using the connection string.

Compile the code and run it again. It should work. If still the database related error is coming it means that the connection string is not correct.

Some of the other links which talk about the same issue are:
http://blogs.neudesic.com/blogs/pete_orologas/archive/2006/06/14/162.aspx
http://daron.yondem.com/CommentView.aspx?guid=cb37f9ff-81d3-4b9c-ab97-18e9eddd9a27

Wednesday, January 9, 2008

How to add tag cloud to your blog?

Tag cloud is a cool technique that is used to categorize your posts, bookmarks, articles. The del.icio.us site is one of the most popular place where you can find the tag cloud use in action. Tagging (as it is commonly called) is one of the Web 2.0 feature.

The default templates available on blogspot don't give you the feature of tag cloud.
In order to add the tag cloud to your blog site follow the steps as explained in the following link
http://phy3blog.googlepages.com/Beta-Blogger-Label-Cloud.html

You will realize that Tag cloud is one of the example of how use of some scripting in a language like Javascript or perl along with CSS can increase the utility of a web site.

Monday, January 7, 2008

USE CASE
  • The use case describes the system’s behavior under various conditions as it responds to a request from one of the stakeholders, called the primary actor.
  • The primary actor initiates an interaction with the system to accomplish some goal.
  • Different sequences of behavior, or scenarios, can unfold, depending on the particular requests made and conditions surrounding the requests
    • Primary actor is the one with the goal that the use case addresses
    • Scope identifies the system that we are addressing
    • Preconditions and guarantees are the things that must be done for the success of the use case.
    • Main Success is the case in which nothing goes wrong
    • Extensions suggest what can happen if something goes wrong in the main success steps

We can put the logging and some of the simple settings as the preconditions since the stress should be to capture the important scenarios
I think that the extensions are the if conditions., At every step we need to ask a question what are the possible alternatives.
Importnt: (page 22): Anyone writing the usecases for a new system to be designed will write blackbox use case and so not discuss the internals
One should not get caught in too much rigor while designing a use case it is costly.
Use cases provide scaffolding that connects information in different parts of the requirements

Usecases add value since they announce a list of goals that help to figure out what the system is going to provide.

Steps to be done in order to write the use cases
  1. Find out the actors and goals
  2. Write the main success scenario
  3. figure out the failure conditions
  4. figure out the failure handling measures for the failure conditions found in step 3


The usecase should be written in a single grammatical form
suD : System under Discussion

Some of the actors are hidden, they are very much required but they are not the ones who are starting the use case. For eg logging system. It is required but it runs in the background and do not initiate a use case. Such actors are called offstage actors.

Scope

Functional scope:It refers to the services provided by the system. It will eventually be captured by the system.
One should prepare a list of actor-goal . This will make clear what are the goals achieved by a particular actor.
Brief is the 2-6 line description of the use case. The main stress is to mention the significane of the use case.

Design Scope:
It means identifying the software and the hardware that will be the part of the system. Depending on the hardware used the behaviour may change. for e.g. printing using a home laser printer is different than printing in a printing press.
The various scopes are : Enterprise, system, subsystem

Depending on the level of the usecase the details will change. The Enterprise will be a top level while the subsystem level will be dealing about how the internal works.


Stakeholders
A stakeholder is someone with a vested interest in the behavior of the use case, even if they
never interact directly with the system offstage actors.

The inclusion of these actors help in improving the quality of the use cases. They may appear in the logs,checks, validations.

The usecase need to protect the interswets of these satkeholders

Primary actor is often but not always the one to trigger the usecase. ( for e.g in case of the time based trigger the primary actor does not triggers the usecase)

Primary actors are important only at the begining and the end of the usecase. In bvetween they dont play a role, so even if we dont identify the primary actor properly not much damage will happen to the system
use some generic names for the primary user so that any alternative user with correct rights can execute the usecase

Supporting actor is an external actor that provides some kind of service to the system under design. e.g. printing service ( we can also call it as secondary actor);

An actor can be a primary axctor in one use case while a supporting actor in another
when we look into the system and name the componenet and their behavior we treat the system as white box.

There are more than just two actors in a white-box use case, since the components of the system are being
shown as well as the external actors

It is extremely rare and usually a mistake, to write white-box use cases as behavioral requirements
for a computer system to be designed


Three Named Goal Levels ( the level of the usecase)

1. summary goals
2. User Goals
3. Sub functions

User Goal
The user goal is the goal of greatest interest. It is the goal the primary actor has in trying to get
work done, or the user has in using the system at all.
A user goal addresses the question, "Can the primary actor go away happy after having done
this?" It should normally be executed in one sitting and should not take more than 30 min
  • complete an purchase order or log on the system are not the user goals
  • buy a book, register a new customer are user goals


Summary level
Summary level goals involves multiple user goals they solve three purposes:
1. They show the context in which the user goals operate
2. they show life-cycle sequencing of the related goals
3. They show the table of contents for the lower level use cases
Summary level use case run for more time they may take days to complete. this happens becase a summary level use case consist of number of user level use cases

They can be found by asking a question "why is the actor doing this?"

Subfunction use case:

These are the use cases that are required to caryy any small step in case of a use case e.g find a customer, save as a file
  • Put a lot of energy into detecting the sea-level use cases. These are the important ones
  • Write a few outermost use cases, to provide context for the others
  • When you ask a question "Why ?" you get into one higher level.
  • When you ask a question "How?" you get into one lower level.


Preconditions, Triggers, guarantees

Precondition is what the system will ensure before letting the usecase to start. Having a precondition means that somebody has already run a usecase to set up the system for this particular usecase

Minimal guarantees are the least promises that can be made to the stakeholders when the primary actor goals cannot be delivered. They are of interest when the goal is abondoned. common guantees " System logged on how far it goes"

Success Guarantee: it states what interests of the stakeholders are satisfied ion the sucesful completion of a usecase either at the end of the main success path or the alternate path

Webservices

The web service can be easily used in the Flex 2. The web service may be in any language. The client can be made to consume the web service. There are two main ways to do that.


First method

<mx:WebService id="WShello" wsdl="http://localhost:2091/CreditCard/CreditCard.asmx?wsdl">

<mx:operation

name="HelloWorld" result="typeRPCResult(event)">

</mx:operation>

<mx:operation

name="ListFiles" result="showFiles(event)">

</mx:operation>

</mx:WebService>

In this case we make use of mx:webservice Tag. We need to specify the location of the WSDL file.

Then we specify the various operations we want to perform. My advice is mention only the functions that don’t want any parameter to be passed.

Result specify the function to be called once the data has arrived.

The event is of resultEvent type

Now in order to get the data we need to call the webservice. This is done by

WShello.HelloWorld.send();

i.e. Webservice_object. Operation_name. Send();

Once the result has arrived the general prototype of the function called is

Private function function_name(evt:resultEvent):void

{
//here you should typecast the event.result into the expected type

var s:string=(event.result as String);

}

Second Method

This method uses more of a programmatic approach. The main use of this method is to call the webmethods that require paramters to be passed to them

The various steps to be followed are:

1. declare an object of type websevice

public var webse:WebService = new WebService();

2. Call a function that will initialize the object

public function callWebMethod():void{

3. Inside the function you need to specify the wsdl file

webse.wsdl="http://localhost:2091/CreditCard/CreditCard.asmx?wsdl";

4. load the wsdl

webse.loadWSDL();

5. Once loaded wsdl file will generate a LoadEvent. We need to call a function on that event so that the necessary webmethod can be called

webse.addEventListener(LoadEvent.LOAD, onWSDL);

onWSDL is the method to be called

6. private function onWSDL(event:LoadEvent):void{

is the prototype for the function. Note that the event type is LoadEvent. The firast parameter in the eventListener call will specify the kind of event that will happen.

7. Before actually calling the webmethod register an helper method that will handle the results arrived from the webmethod

webse.GetFile.addEventListener(ResultEvent.RESULT, onGetFile);

specify the webmethod_name.addEventListener

Note that the event type is ResultEvent

8. Call the webmethod passing the correct parameter

Webse.GetFile(parm1.parma2…)

9. Handle the result in the onGetFile() function

Private function onGetFile(event:ResultEvent):void{

}

10. type cast the event.result to the type you require

var s:string=(event.result as String);

In my sample code I have typecasted it to an object, since the webservice will be returning a complex data type

var ob:Object=(event.result as Object);


The object is then used to populate WebFileData object.





The following is the code snippet that make use of both of the methods.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.soap.LoadEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import valueObject.*;
[Bindable]
private var arc:ArrayCollection = new ArrayCollection();

private var theWF:WebFileData;

public var webse:WebService = new WebService();
//convert the result into the type that is returned.
public function typeRPCResult(evt:ResultEvent):void{
hell.text=(evt.result as String);
}
// what ever is returned convert the result into that.
public function showFiles(evt:ResultEvent):void{
arc=(evt.result as ArrayCollection);
}

//function to initialise the webservice (THE SECOND METHOD)

public function callWebMethod():void{
webse.wsdl="http://localhost:2091/CreditCard/CreditCard.asmx?wsdl";
webse.loadWSDL();
// the eventhandler that will be called when the loadevent happebns
webse.addEventListener(LoadEvent.LOAD, onWSDL);
}

/**
* function to display the results from the web service
**/
private function onWSDL(event:LoadEvent):void{
Alert.show("wsdl loaded");
// register the eventhandler that will be called once the result is back
webse.GetFile.addEventListener(ResultEvent.RESULT, onGetFile);
var tempString:String=txtFile.text;
var tempFileName:String;
//fileName = fileName.substr(fileName.lastIndexOf(“/”) + 1);
tempFileName=tempString.substr(tempString.lastIndexOf("\")+1);
hell.text=tempFileName;
//Alert.show(hell.text);
webse.GetFile(tempFileName);
}

// this function will be responsible to render the result on the panel
private function onGetFile(event:ResultEvent):void
{
var ob:Object=(event.result as Object);
//you dont need to specify new here , since the createWF function will take care of it
theWF=WebFileData.createWF(ob);
//hell.text=theWF.CreationTime.date.toString();
resName.text=theWF.Name;
resContent.text=theWF.Contents.toString();
resCD.text=theWF.CreationTime.toDateString()+" "+theWF.CreationTime.toTimeString();
resLAT.text=theWF.LastAccessTime.toDateString()+" "+theWF.LastAccessTime.toTimeString();
resLWT.text=theWF.LastWriteTime.toDateString()+" "+theWF.LastWriteTime.toTimeString();


}

// to invoke the web methods
private function init():void{
WShello.HelloWorld.send();
WShello.ListFiles.send();
}



]]>
</mx:Script>
<!-- this is one of the ways to define the web services (THE FIRST METHOD) -->

<mx:WebService id="WShello" wsdl="http://localhost:2091/CreditCard/CreditCard.asmx?wsdl">
<mx:operation name="HelloWorld" result="typeRPCResult(event)">
</mx:operation>
<mx:operation name="ListFiles" result="showFiles(event)">
</mx:operation>
</mx:WebService>

<mx:HBox>

<mx:VBox>
<mx:Label id="hell" />
<mx:List id="ls" dataProvider="{arc}" rowCount="{arc.length}" />
</mx:VBox>
</mx:HBox>
<mx:Panel x="221" y="10" width="500">

<mx:Label text="You have selected:"/>

<mx:Text id="txtFile" width="400" text="{ls.selectedItem.toString()}"/>

<mx:Button name="btnGet" label="Copy" click="callWebMethod()" />



</mx:Panel>
<mx:Panel x="221" y="114" width="500" height="268" layout="absolute" title="The Result">
<mx:Canvas x="10" y="0" width="100%" height="100%">
<mx:Label x="10" y="26" text="Name:"/>
<mx:Text x="60" y="26" width="213" height="18" id="resName" text="xx"/>
<mx:Label x="10" y="52" text="Content"/>
<mx:TextArea x="67" y="51" width="248" height="43" id="resContent"/>
<mx:Label x="10" y="117" text="Creation Date"/>
<mx:Text x="109" y="117" width="206" id="resCD" height="18"/>
<mx:Label x="10" y="143" text="LastAccessTime" width="93"/>
<mx:Text x="121" y="141" width="180" id="resLAT" height="20"/>
<mx:Label x="10" y="169" text="LastWriteAccess" width="93"/>
<mx:Text x="131" y="169" width="170" id="resLWT" height="18"/>
</mx:Canvas>
</mx:Panel>

</mx:Application>


/*****************************/
The WebFileData class


import flash.utils.ByteArray;
import mx.rpc.soap.*;
import mx.charts.chartClasses.DataDescription;
[Bindable]
public class WebFileData
{
public var Name:String;
public var Contents:ByteArray;
public var CreationTime:Date;
public var LastAccessTime:Date;
public var LastWriteTime:Date;
public function WebFileData(_Name:String,_Contents:ByteArray,_CreationTime:Date,_LastAccessTime:Date,_LastWriteTime:Date){
this.Name=_Name;
this.Contents=_Contents;
this.CreationTime=_CreationTime;
this.LastAccessTime=_LastAccessTime;
this.LastWriteTime=_LastWriteTime;
}
/**
* The function will accept the parameter of type object and then it will fill the datastructure and
* return back the object
**/
public static function createWF(o:Object):WebFileData{
var WF:WebFileData=new WebFileData(o.Name,o.Contents,o.CreationTime,o.LastAccessTime,o.LastWriteTime);
return WF;
}

}