Wednesday 28 November 2012

TSQL Insert multiple values using a single insert statement


INSERT INTO TargetTable (Column1, Column2)
SELECT 'Value1', 'Value1'
UNION
SELECT 'Value2', 'Value2'
UNION
SELECT Column1, Column2
FROM SourceTable

Monday 12 November 2012

ASP.NET: System.Web.HttpException (0x80004005)

Error:
System.Web.HttpException (0x80004005): The URL-encoded form data is not valid. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)


Resolution:
Web.config:

<configuration>
<appSettings>


            <add key="aspnet:MaxHttpCollectionKeys" value="5000" />
            <add key="aspnet:MaxJsonDeserializerMembers" value="5000" />



If ASP.NET 1.1:
Add the following key to the registry:


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\1.1.4322.0\MaxHttpCollectionKeys

Value: 5000

Reference:
http://support.microsoft.com/kb/2661403

VS.NET 2003 Error: The project you are trying to open is a Web project. You need to open it by specifying its URL path.

- Create a new webinfo file, for example for the project file: proj.vbproj:
"proj.vbproj.webinfo":
<VisualStudioUNCWeb>
    <Web URLPath = "http://localhost/CAMS/Workflow/proj.vbproj" />
</VisualStudioUNCWeb>

 - Open the solution and "Add Existing project"

Sunday 11 November 2012

Date validation using JavaScript function


sub isvaliddate {
  my $input = shift;
  if ($input =~ m!^((?:19|20)\d\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$!) {
    # At this point, $1 holds the year, $2 the month and $3 the day of the date entered
    if ($3 == 31 and ($2 == 4 or $2 == 6 or $2 == 9 or $2 == 11)) {
      return 0; # 31st of a month with 30 days
    } elsif ($3 >= 30 and $2 == 2) {
      return 0; # February 30th or 31st
    } elsif ($2 == 2 and $3 == 29 and not ($1 % 4 == 0 and ($1 % 100 <> 0 or $1 % 400 == 0))) {
      return 0; # February 29th outside a leap year
    } else {
      return 1; # Valid date
    }
  } else {
    return 0; # Not a date
  }
}



This is an excerpt from another community work.

Execute an application in another security context on Windows

runas /user:test@domain iexplorer.exe

Identifying Active directory group members using TSQL on MS SQL Server

exec master.dbo.xp_logininfo 'DomainName\GroupName','members'

Prerequisites: Requires membership in the sysadmin role for the database server.
Requires EXECUTE permission for this stored procedure within the master database.

P.S.
By experiments, I  noticed that I could enumerate only members for groups to which I belong.

TSQL update sample using Join (Update multiple rows)



Update PA
SET PA.ActionID= A.ID
FROM ActionDates PA
LEFT JOIN Action A ON PA.Action = A.Name
AND PA.PhaseID=A.PhaseID