Code Project

Link Unit

Wednesday, September 15, 2010

Procedure has no parameters and arguments were supplied

Problem : Procedure has no parameters and arguments were supplied

Stored procedure code

ALTER procedure [dbo].[GetCompany]
select * from Company

Method which calls the above procedure

public void RefreshCompany()
SQLCommand command=new SQLCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "GetCompany";
da.SelectCommand = command;
catch (Exception ex)
throw new Exception(ex.Message);

Now the problem is that first time everything is fine, but when the application calls it again (e.g. refresh after update)
it throws the exception "Procedure has no parameters and arguments were supplied". As it is evident that stored procedure does not actually expect any parameters.
It is just a plain select statement

The same command object was used in all procedure calls, and it's caching the parameters of earlier call to another procedure

command.parameters collection wasn't cleared.

#1 command.parameters.Clear() => Clear the parameter cache.
#2 Use another command object for each query / procedure call.

Hope it helps
Jatinder Singh

Tuesday, July 27, 2010

Multi-Value Columns in SharePoint Designer Workflow

Requirement :

Create a workflow so that any new item created in the list should fire the mail to recipients.

#1 Create a Multi value column in a list

#2 Now on creation of new item attach the workflow to send the mail.

The multi value column is missing in workflow .The SPD suffers from a deficiency in the workflow component ,which doesn't allow you to send e-mail to multiple recipients from a multi-value column of a list using SharePoint Designer 2007 (SPD).

Solution #1

Turn off "Allow multiple selections" for your column (note the warning "This will remove all person values except the first one") . Now you should be able to provide the column as lookup column in workflow.

Change the workflow and then turn "Allow multiple selections" on for your column.

This solution is not acceptable as it removes all the values except first value. So the approach is good till development but once workflow goes to production you won't be able to touch the workflow or list where you would like to turn off "Allow multiple selections"

Solution #2

Create a variable var _employees in workflow

Set the value of variable "_employees" to your "multi value column".

Send the email using the variable "_employees"

The second solution is simple and elegant.

I hope it helps.

Monday, July 26, 2010


Though LOC for estimation is not very reliable , but still in case you need to find LOC of existing project. One way is to write a piece of code in your preferred language C#/VB.Net etc or another way is using some command like wc -l as in Linux.
In DOS there is no such command directly availiable , so how to go about this one?? I assume nobody is going to write pharse "I am genius" in deployed code.
So the trick is to find nonexisting text[/v] in lines and count those lines [/c]. For this to work copy all the source code files in one directory and run the following
C:\CS> find "I am genius" /c/v *.cs >ABC
Hope it helps

Filtering By ListTextField for GridDropDownColumn

We were using Radgrid for displaying/Editing information and to filter rows we were using filter mechanism as given by RadGrid. The issue faced was that we were unable to filter the rows on the GridDropDownColumn , so we tried to follow the suggestion as given at telerik site

We tried the suggestion #1 , everything was fine for display purpose. But as soon as we try to edit or Add a new row we were able to view both Hidden GridBoundColumn and GridDropdownColumn , and the value of both were getting passed to the objectdatasource we had for DML operations.

Now to solve the problem we used "readonly=true" for GridBoundColumn and it simply disappeared from edit form.
In case editable column types (column types that implement the IGridEditableColumn interface) have a ReadOnly property that determines whether the column editor is visible in the edit form. When ReadOnly is True, the column editor does not appear in the edit form. ReadOnly does not affect whether the column is visible in browser mode.

I hope it helps

Tuesday, June 08, 2010

Access site column in Subsites

We have created a site collection and under it many sites and subsites, now our aim was to create some basic lists like state , city,country etc at the top level site and refer the same across all the subsites. We faced the problem ,where in a lookup column you can only refer the lists of current site. In order to add one of the columns from a Parent site list in a subsite list we did the following .
1. Create a site column. - In parent Site Go to Settings -> Site Column. Here Create a new site column and choose the type as Lookup. Get the Lookup Information from Another list and Select your Parent list and its realted Column.
2. Add site Column in your Subsite's list - Now go to your subsite list and goto list settings. Under Columns add a existing site column and select the above created custom column.
Hope it helps

Workflow stuck at Starting

Workflow stuck with "Starting" status is probably the most difficult to debug because there are generally no diagnostic entries in the ULS logs or event logs to point you to a problem.
The problem we faced at our work place is that all setting are as per this blog post .
1 Environment is properly configured with the SSP and everything set up correctly as mentioned in the blog.
2. Windows Sharepoint Timer service is up and running.
3. Domain account was used for configuring SSP.
Even after doing all the stuff workflows were getting stuck with a "Starting" status.
We have a custom workflow attached to a Document library and it is supposed to trigger when a new item is added or changed. The library has the 'require check out before editing' setting enabled so even a manual document upload to the library would first check the document in and then you'll be presented with the screen for providing any required metadata and once you are through that THEN the workflow would trigger (workflow requires a document to be checked-in before it can start).
So disabling the 'require check out before editing' solved the issue for us.

Monday, April 05, 2010

Skin not Applied to RadDatePicker inside UpdatePanel

We were facing this issue where the skin was not applied to the RadDatePicker , in case it is placed inside an UpdatePanel. After searching for a solution it was observed that atleast one DatePicker Control should be placed outside the UpdatePanel. Now the rest of the process becomes easy , we need to hide that dummy Datepicker control once the rendering is complete.
Code in aspx file

<aspx:updatepanel id="UpdatePanel1" runat="server">
<!-- Put your content here -->

<radcln:raddatepicker id="radDt" runat="server" displaydateformat="dd-MMM-yyyy" dateformat="dd-MMM-yyyy" width="100px" mindate="1/Jan/1900"></radcln:raddatepicker>

In code behind.
protected void Page_PreRenderComplete(object sender, EventArgs e)
radDt.Visible = false;
we can put the aspx and code behind segments in .master page , so all pages reflect the same.
Hope this helps.

Monday, March 22, 2010

DoesUserHavePermissions in WebPart

I wrote a search webpart and it need check if the current user has the right to some lists so I can highlight those lists in different color , but Whenever SPList.DoesUserHavePermissions is called on the object[List/Library], for the user who does not have the permission, it should return false, but it gives an exception. An IE browser pops up asking for user to type in username and password. This dialog box should not appear as my code catches the exception.
Solution: After googling around for some solution on the same line , found points which may help fellow visitors.
#1 DoesUserHavePermissions only works in WSS, not SPS
#2 Suppress Popup for Unauthorized Access:The problem happens with your SPSite object from which you get the web, then the list, there is a property called CatchAccessDeniedException, you should set it to false, then make your call, end the popup will not show up. This is a standard WSS feature, and will happen every time you try to access a resource to which the current user does not have access.
WorkAround : Use the following in your webpart

using(SPWeb oWeb=SPContext.Current.Web)
oSite.CatchAccessDeniedException = false; // Suppress the popup
SPListCollection oList = oWeb.Lists;
oList.ListsForCurrentUser = true;
int iCount = oList.Count;
for(int i=0;i{
if(oList[i].Permissions.DoesUserHavePermissions(SPRights.ViewListItems)) // Check for view Rights
// Do something
catch(System.UnauthorizedAccessException ex)
//Do Nothing, or as you please

Hope this helps

Wednesday, February 03, 2010

When caching is enabled for the XmlDataSource that is control tree it requires a UniqueID that is unique throughout the application

We were using XmlDataSource in code behind and assigning the same to a menu.
XmlDataSource XmlMenu = new XmlDataSource();
This was resulting in "When caching is enabled for the XmlDataSource that is control tree it requires a UniqueID that is unique throughout the application" - Use an ID for XmlDataSource .
The solution for which is specifying the ID of XmlDataSource .
XmlMenu.ID = "Menu1";
Reason:XmlDataSource class internally calls a private method called CreateCacheKey.Now, if you are using XmlDataSource without an ID in Code-Behind. This might throw an exception - "When caching is enabled for the XmlDataSource that is not in the pages control tree it requires a UniqueID that is unique throughout the application." This is due to the absence of the UniqueID ,which is used as part of the caching key.Without ID all instances would try to use same caching key. Setting a distinct ID will resolve the problem.

Monday, February 01, 2010

Change default language from VB to VC#

Visual Studio 2005 is installed on all of our development PCs.Initially our projects were in VB so while installing we choselanguage "Visual Basic" instead of "Visual C#.Now .We are working more on C# and when a new project/site is to be created, we should take care which language we chose otherwise it will get created in default language which is VB in our case.So we wanted to have VC# as our default lanaguage. Searched google/newsgroups to figure out solution.

#1. We can do this by using Registry by changing this registry key:HKCU\Software\Microsoft\VisualStudio\8.0\General\NewProjectDialogPreferredLanguage. It was VB in our case we can change it to VC#. The same key also exist in HKEY_USERS. We might do a search for that value name and just change to VC# anywhere you find it.Though this option is not preferrable.

#2 If we wish to remove VB and use only C# in our programming environment then we could do that using add/remove programs and click on change button for the installation. Just uncheck vb and check off C#.Though this option is also not preferrable.

#3 The easiest option to do so is
a) Choose Tools -> Import and Export Settings...
b) Select Reset All Settings and click Next
c) Select whether you would like to save the current settings and click Next
d) Select the settings you want to use(change the language to VC#) and click Finish

Hope it helps the visitor.

Friday, January 29, 2010

Exception Details: System.Runtime.InteropServices.COMException: Access is Denied

"Access Denied" : Error was creeping when we are tring to load the crystal report file by using Load("~/Reports/MyReport.rpt"); The error looks silly as it is not pointing where the access should be given. After doing bit of googling and applying/reverting the changes found the solution.
Reason & Solution
When a CR[Crystal Report] is being created in ASP.NET, the .NET will create a report file in a temp folder, e.g. C:\Documents and Settings\MachineName\ASPNET\Local Settings\Temp.
#1 You can try to give ASPNET permission for this folder.
#2 You can also update web.config to impersonate.

<authentication mode="Windows">
<identity impersonate="true"
password="mypassword" />

I preferred the #1 solution ,as it is easier to give permissions once on the folder; You may like to try option #2 but keep a note that whenever Domain[very rare],user or password changes at that point web.config needs to be updated.

Hope it helps

Monday, January 25, 2010

TNS-3505 Failed to resolve name

On the primary database the current tnsnames.ora config for the db in
question looks like this :

(SID = live)

This works ok - tnsping etc ...

now when I try to add an entry for <dbname>_PRIMARY or

(SID = live)

I get a TNS-3505 Failed to resolve name.
I tried various combinations but none worked.

After doing lot of comparsion with existing files TNSNAME.ORA , it appeared that nothing is wrong.
Giving the new entry a closer look revealed that minor difference ,a leading whitespace[space on left] exist . Removed that extra space , all worked fine.

Hope it helps