Wednesday, March 24, 2010

Using Server.Transfer

This is somewhat complex but sophisticated method of passing values  across pages. Here you expose the values you want to access in other  pages as  properties of the page class. This methods require you to code extra  properties that you can access in another web form. However, the efforts  are worth considering. Overall this method is much cleaner and object  oriented than earlier methods. The entire process works as follows:
  • Create the web form with controls
  • Create property Get procedures that will return control values
  • Provide some button or link button that posts the form back
  • In the button click event handler call Server.Transfer method that will transfer execution to the specified form
  • In the second form you can get a reference to the first form instance by using Context.Handler property. Then you will use the get properties we created to access the control values.
The code to accomplish this is somewhat complex and is shown below:
Source Web Form
Add following properties to the web form:
public string Name
{
get
{
return TextBox1.Text;
}
}

public string EMail
{
get
{
return TextBox2.Text;
}
}
Now, call Server.Transfer.
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}
Destination Web Form
private void Page_Load
(object sender, System.EventArgs e)
{
//create instance of source web form
WebForm1 wf1;
//get reference to current handler instance
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
}

Fault Exception in WCF

calling the FaultException in Catch block

catch (Exception ex)

{

throw ex ;

// useful when FaultException attribute is mentioned in the web method called.

//with method declaration in interface.

////[FaultContract(typeof (MyFaultException))]

//MyFaultException myException = new MyFaultException();

//myException.Reason = "Reason for this error is : " + ex.Message.ToString();

}

Fault exception definition

// optional but a good practice.

[DataContract]

public class MyFaultException

{

private string _reason;

[DataMember]

public string Reason

{

get { return _reason; }

set { _reason = value; }

}

}

Thursday, March 18, 2010

How to Deploy and Test An SSIS Package

When working with SSIS, it is not immediately obvious how to deploy a package. Following are my short notes on deploying an SSIS package*.

Deploy the Package

  1. While in the Package designer, choose Project > [Package Name] Properties. The Configuration manager dialog will appear.
  2. Choose Deployment Utility from the tree.
  3. Change the CreateDeploymentUtility option from False to True. Note the DeploymentOutputPath variable. Push OK to close the dialog.
  4. Open the Solution Explorer and right-click on the .dtsx file and choose Properties. Copy the Full Path variable and use it to find the bin\Deployment folder.
  5. Locate the [Package Name].SSISDeploymentManifest file. Double-click on the file and follow the steps outlined by the wizard to deploy the package.

Test the deployed Package

  1. Open MSFT SQL Server Management Studio and choose Connect > Integration Services from the UI. Choose the Server and connect.
  2. The packages will be saved under the MSDB folder. Right-click on the package to run it.

---

* To re-deploy a package, follow steps 1-5 again.

Assigning a value to an ASP.Net CheckBox

Unlike the html checkbox, the ASP.Net CheckBox control does not have a value property. However, you can add attributes via markup as well as pragmatically via code. Markup:
<asp:checkbox id="CheckBox1" runat="server" value="'<%# Eval(" valuecolumn="">' /> <asp:checkbox id="CheckBox2" runat="server" value="'2'">
Only Eval can be used to bind to "custom" attributes, as compared to properties built into the control which also work with Bind Code:
CheckBox2.Attributes.Add("Value", 2);
The "Add" method add takes two parameters. The first parameter is the name of the attribute . The second parameter is the value for this attribute. This adds a server accessible attribute for the value, the attributes collection is maintained via the viewstate. However the CheckBox control does not render the value attributed (it actually removes the attribute during the render event phase. However, if you want to add the attribute so it is rendered via html then the checkbox has a property called InputAttributes, adding properties to this collection will always be rendered in the html. Code: CheckBox2.InputAttributes.Add("Value", 2);</asp:checkbox></asp:checkbox>

ASP.Net Trace stops showing up

I've noticed that when using asp.net 2.0 dev server that the trace would only show up on one or two pages. I decided to do some research into it and found out it has to do with the trace section of webconfig. There is a attribute called requestLimit whose limit was set to 20. After 20 requests the trace just stops showing up. 20 requests may not sound that bad but with the dev server all requests (including images and everything) go through the asp.net runtime so one page with my website would have 20 requests for other resources. I found out that there is another attribute called mostRecent which when set to true will discard older requests rather than stop working. I also didn't read the note in the webconfig about "you can view the application trace log by browsing the "trace.axd" page from your web application root".