Code Project

Link Unit

Thursday, August 09, 2012

Login failed for user 'domain\machinename$'

We faced an error "Login failed for user 'DOMAIN\MACHINENAME$'" while for Web Application setup we were having SQL Server on one machine and IIS server on another.

Reason:
NETWORK SERVICE and LocalSystem will authenticate themselves always as the correpsonding account locally (builtin\network service and builtin\system) but both will authenticate as the machine account
 if connecting to remote system.

it means that a process running as NETWORK SERVICE or as LocalSystem has accessed a remote resource, has authenticated itself as the machine account and was denied authorization.

When access is denied to a machine account, then access must be granted to the machine account. If the server refuses to login 'DOMAIN\MACHINE$', then you must grant login rights to 'DOMAIN\MACHINE$' not to NETWORK SERVICE. Granting access to NETWORK SERVICE would allow a local process running as NETWORK SERVICE to connect, not a remote one, since the remote one will authenticate as, you guessed, DOMAIN\MACHINE$.

Solution:
Create login in SQL Server for client machine .
Make required "User Mapping" for databases to whatever we wish to access

List of all probable reasons and solutions http://msdn.microsoft.com/en-us/library/ab4e6cky%28v=vs.80%29.aspx
For us this option worked : If SQL Server is running on a remote computer and the Web server is running IIS 6.0, give the Web server's machine account login privileges on the remote computer. The machine account is referenced as DOMAIN\MACHINENAME$.

Hope it helps.

Friday, August 03, 2012

SalesForce Query is either selecting too many fields or the filter conditions are too complicated.


I get the following error when I try to replicate the custom object: Query is either selecting too many fields or the filter conditions are too complicated.

Even a simple query like Select * from SalesForce...Object was also returning same error.



Reason
This error is from the salesforce.com server and occurs when the table has too many formula fields for the salesforce server to return query results. Internally at the salesforce server, when a query occurs the select list is modified and the calculated fields are replaced with their formulas. Then the sf server tries to execute it and determines that the query is too complex.
 
Solution
You could try using a feature of DBAmp called Column Subsets which allow you to replicate subsets of columns of a table and then glue them together locally. This effectively decreases the number of formula fields in the query. See Column Subset Views in Chapter 2 of the DBAmp doc.

exec sf_replicate 'SALESFORCE','Object_ColumnSubsetAM'
exec sf_replicate 'SALESFORCE','Object_ColumnSubsetNZ'


and then use following to construct the table

Select column1,column2,column3 into Object
from Object_ColumnSubsetAM AM
inner Join Object_ColumnSubsetNZ NZ on AM.id = NZ.id

Alternatively, you can just construct multiple select statements yourself with subsets of the columns.

Monday, May 28, 2012

Error: The GetBytes function can only be used on columns of type Text, NText, or Image

On running a simple statement like

Select * from TableABC

and following error was encountered.

An error occurred while executing batch. Error message is: Invalid attempt to GetBytes on column 'XYZ'.
Error: The GetBytes function can only be used on columns of type Text, NText, or Image.

Reason:
After we checked the version of SSMS we noticed that connecting to the 2008 instance with a 2005 SSMS client was the issue. Essentially it means that SSMS doesn't understand one of the column data types coming back to it like datetime2

Solution:
Connected with SSMS 2008 and it all worked again.

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]
AS
begin
select * from Company
end


Method which calls the above procedure

public void RefreshCompany()
{
try
{
SQLCommand command=new SQLCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "GetCompany";
da.SelectCommand = command;
da.Fill(StaticValues.data.Tables["Company"]);
}
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


Cause:
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.

Solution
#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

LOC in DOS

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 http://www.telerik.com/help/aspnet-ajax/grdfilteringbylisttextfieldforgriddropdowncolumn.html

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.
Explaination
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