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.