Monday, January 30, 2012

Debugging webpart

It was very helpful in knowing how to fix the breakpoint and debug the code for custom written webpart during a sharepoint pageload event.

1. Browse the sharepoint site.
2. Use Debug -> Attach to process from the webpart which is kept open in .net env. Choose the w3wp process from the list.
3. When the page which uses the webpart is loaded, we can see the breakpoint hit.

Note, To spot the actual w3wp process which points to the site, we use this,
1. Open a notepad
2. Type

"C:\windows\system32\inetsrv\appcmd.exe list wp

3. Save the notepad as "WProcess.cmd"
4. Double click the cmd file which will list the port against the process id.

Custom Webpart in sp2010

Creating and hosting webpart in sp2010

I recently had a chance to edit an existing custom written webpart and host it in sp2010. It was like we already had an usercontrol in place. Entire functionality was developed inside the usercontrol and it was loaded inside the webpart.

Add a safecontrol entry to the web.config like

Later it was built. The dll from the debug folder is copied and pasted to the bin folder of the virtual directory. And the same was placed in GAC (C:\Windows\assembly).

After refreshing the virtual directory and recycling the application pool. We should be able to browse the sp page in which the webpart was included.

Webservice - Creating and hosting

I had a requirement to write a webservice in windows server 2008 with IIS 7. So this is just a summary of the things we did and the troubles we came across,

Step - 1 : Writing the code behind


public DataSet getOrderDetails(string OrderNumber)
OracleConnection con = null;
OracleCommand cmd = null;
string query
= String.Empty;
query = "Select * from table_name where CUSTOMER_PO = '" +
con = new
cmd = new OracleCommand(query, con);
DataSet orderDataSet =
new DataSet();
OracleDataAdapter adapter = new OracleDataAdapter(cmd);

return orderDataSet;

catch (Exception e)
query = e.Message;


Step -2: Deploying
1. Publish the webservice.
2. Create a virtual directory in IIS
3. Bind the published webservice path to the virtual directory created.
4. In IIS 7, individual app pool is created for every virtual directory.
5. Browse the application link(find in the right side) to view your application.

Possible troubles/errors/exceptions
1. If we are not able to view the webmethods writen, Possibly the directory browsing is not enabled. We can enable it. It is quite simple.

2. If the same webservice is accessed from different server, We may not get the input box to enter the user data. In this case web.config should be modified to include this block,


3. TNS entry error- This is a very often error which can be solved by just having an entry for the datasource, in the TNS file which can be found somewhere similar to C:\Orawin\network\admin

It happened to me like, my code was working perfect with all the servers except with the development environment.

Later we found that the dev server was 64 bit which caused the problem. So we made changes like building the code in X64 configuration/ enabling or disabling 32 bit in IIS. We replaced Oledb with Oracle connection and replaced the conn string with the actual TNS entry.

Finally having the reference "using Oracle.DataAccess.Client;" and modifying the connection object like
"con = new OracleConnection("Actual TNS entry");" and it worked.

Friday, September 14, 2007

Tree View in Dropdownlist

We all are very much aware of the DropDownList(a server control available in asp .net), the way it functions and the way the data are listed in it.

eg .,
There is another server control available which is < asp:TreeView > which gets rendered something like this


I was wondering whether it is possible to have this tree view inside the dropdown. To start with, I tried binding the dropdown with the treeview and then with xml having various sub levels but I couldn't make up.

So I tried combining the available controls which will produce the look and feel of a drop down box with a tree view. A textbox, button(probably loaded with down arrow image) and a treeview were chosen. To make it behave like a dropdown, the visibility of the div which contains the tree view can be controlled.


protected void downArrowButton_Click(object sender, EventArgs e)
treeViewDiv.Visible = true;

Now, we have a list of items displayed in a tree like structure when the down arrow button is clicked. And when any option is selected the text box should be loaded with it and the tree structure should not be visible in order to make it behave like a drop down box. The code goes something like this,

protected void stateTreeView_SelectedNodeChanged(object sender, EventArgs
if (sender.GetType().ToString().EndsWith("TreeView"))
cityTextBox.Text = stateTreeView.SelectedNode.Text;
treeViewDiv.Visible = false;

This code can further be customised as per one's requirement and can even Ajaxify certain things for better user experience.

The final output which i got was something similar to this,

Makkals, this was my long time plan(to post some technical thing). Kindly bare with me.....

அரசியல்ல இதெல்லாம் சகஜமப்பா!!!!!!

Thursday, September 13, 2007

DateTime format in Sql Server

SQL Server provides a number of options you can use to format a date/time string. One of the first considerations is the actual date/time needed. The most common is the current date/time using getdate(). This provides the current date and time according to the server providing the date and time. If a universal date/time is needed, then getutcdate() should be used. To change the format of the date, you convert the requested date to a string and specify the format number corresponding to the format needed. Below is a list of formats and an example of the output:

How to debug stored procedures in Visual Studio .NET

This step-by-step article explains two ways that you can debug SQL Server stored procedures and the necessary configuration settings and steps for each approach. A Visual Studio .NET developer can use the Server Explorer to debug SQL Server stored procedures independently of any Visual Studio project, or the developer can step into the code of the stored procedure directly from managed code in a Visual Basic, Visual C#, or Visual J# project.Option 1: Debug a stored procedure in standalone mode
Open Server Explorer.NOTE: It is not necessary to add a Data Connection to work with a SQL Server server because SQL Server servers are listed under the Servers node also. You will use the Servers node in the steps that follow; however, you can use a Data Connection to you SQL Server server in the same way.
Under the Servers node in Server Explorer, expand the SQL Server machine name, expand the SQL Servers node, expand the SQL Server instance, expand the Northwind database node, and then expand the stored procedures node.
Right-click the CustOrderHist stored procedure and then click Step Into Stored Procedure.
The Run stored procedure dialog box opens, which lists the parameters of the stored procedure. Type ALFKI as the value for the @CustomerID input parameter and then click OK.
In the Visual Studio design environment, a window opens that displays the text of the stored procedure. The first executable line of the stored procedure is highlighted. Press F11 to step through the stored procedure to completion.
In the Output window, the following message is displayed, which indicates successful execution: The program ‘SQL Debugger: T-SQL’ has exited with code 0 (0×0).
Option 2: Step into a stored procedure from managed code

Create a new Visual Basic Windows Application project.
Drag a Button control from the toolbox to Form1. At the top of the Form1 code window, add the following line of code:
Imports System.Data.SqlClient
Copy the following code into the Button1_Click event procedure:
NOTE: Modify the connection string as necessary for your environment.

Dim cn As SqlConnection
Dim strCn As String
Dim cmd As SqlCommand
Dim prm As SqlParameter
strCn = "Data Source=(local);Initial Catalog=Northwind;" & _
"Integrated Security=SSPI"
cn = New SqlConnection(strCn)
cmd = New SqlCommand("CustOrderHist", cn)
cmd.CommandType = CommandType.StoredProcedure
prm = New SqlParameter("@CustomerID", SqlDbType.Char, 5)
prm.Direction = ParameterDirection.Input
cmd.Parameters("@CustomerID").Value = "ALFKI"
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
Console.WriteLine("Product ordered: {0}", dr.GetSqlString(0))
End While

In Solution Explorer, right-click the project (not the solution) and open the Property pages. Click Configuration Properties in the tree and then click to select the SQL Server Debugging check box on the Debugging page to enable stored procedure debugging.
Set a breakpoint on the following line of code:Dim dr As SqlDataReader = cmd.ExecuteReader
In Server Explorer, locate and open the CustOrderHist stored procedure as described in Option 1. Right-click the stored procedure and then click Edit Stored Procedure.
Set a breakpoint in the stored procedure on the SELECT statement, which is the only line of executable code.
Press F5 to run the Visual Basic project.
When Form1 appears, click the command button. The code will run to the breakpoint that you set before the stored procedure is called.
Press F11. Code execution steps from the ExecuteReader method into the stored procedure window.
Press F11 again. The single line of code in the stored procedure, the SELECT statement, executes. Then control returns to your Visual Basic project, and the project runs to completion.
To continue to step through the Visual Basic code after you step out of the stored procedure, you must set a second breakpoint in the Visual Basic code after the call to the stored procedure. For example, in the sample code shown in this section, you can set the second breakpoint on the following line:While dr.Read

To step from Visual Studio code into a stored procedure, you must enable SQL Debugging in the Project Properties on the Debugging page.

To step through stored procedure code, you must set a breakpoint in the stored procedure itself. Otherwise, debugging steps over the stored procedure and the window for the stored procedure does not open.

To continue to step through Visual Studio code after debugging steps out of a stored procedure, you must set a breakpoint in the project code at a point after the execution of the stored procedure. Otherwise, the code runs to completion after debugging steps out of the stored procedure.

For setup and configuration issues, refer to the section entitled “Setting Up SQL Debugging” in the Visual Studio .NET documentation.
Limitations of stored procedure debugging
The following is a list of limitations that you may encounter when you debug stored procedures and that you do not encounter when you debug Visual Studio code:

You cannot “break” execution.

You cannot “edit and continue.”

You cannot change the order of statement execution.

Although you can change the value of variables, your changes may not take effect because the variable values are cached.

Output from the SQL PRINT statement is not displayed.

Thursday, July 5, 2007


&nbsp;&nbsp;&nbsp; For people who dont know ,the toString() is one of the methods that are available for all objects in java .

Have you ever used this function??

If yes for what you have used this function??

Hmmm Where did i use this function??

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; In date functions to convert date into string ,when you want to assign an object to a string or if you want to print something which is not a string.Basically when you have a sop(System.out.println())it can print only string values and by default it calls the toString() method for all objects.
Calling a toString() method to convert a date to string is ok and even to convert integer or a boolean to string is ok because in both cases the value of the object is returned as a string without any damage .

What happens when you call it for a user-created-class object.?
When you do this you would get an output like this


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; And do we get any idea about the object and its values???
No , we just know that it is not null.
I had used this to check if the value is not null . I was wondering why we have this function for all objects until i knew about the "overridding toString()".

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Every class is supposed to override the toString() method
Overriding toString() is when you want to be able to read something meaningful about the objects of your class. Code can call toString() on your object when it wants to read useful details about your object.

if you have a class name

class Biodata
String name;
String age;
// all functions goes here

public String toString()
return "this is biodata class and my name is "+name+ my age is "+age;

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Now if you try to print the object of this class you will get a detailed idea of this&nbsp; object rather than "@&%$%^!###" .
I guess it is one rule that should be followed.Every class should override toString() method.

Powered by ScribeFire.