SQL script to generate random number and decimal as per row basis


Online project management, task software, and free collaboration workspace: AJAXWorkspace
AJAXWorkspace is a free online workspace that offers task tracking software, team collaboration, online calendar, document sharing, and file management for project management and teamwork.

This is nothing new on how to generate random number as per row basis. I am using NewID() method and complied into SQL function. Just to keep as my own record. Here are the 2 functions which return integer and decimal value.

Function:

 CREATE FUNCTION dbo.udf_GetRandomNumber(
@GUID AS UNIQUEIDENTIFIER,
@MinValue AS INT = 0,
@MaxValue AS INT = 1000
)
RETURNS INT AS
BEGIN
  �
 RETURN ABS(CAST(CAST(@GUID AS VARBINARY) AS INT) % (@MaxValue – @MinValue + 1)) + @MinValue

END

 Usage:

 SELECT dbo.GetRandomNumber(NewID(),100,500) FROM TableA
– Return random number from 100 to 500 as per row basis

Function:

CREATE FUNCTION dbo.udf_GetRandomDecimal(
@GUID AS UNIQUEIDENTIFIER,
@MinValue AS INT = 0,
@MaxValue AS INT = 1000,
@GUIDDecimal AS UNIQUEIDENTIFIER = NULL
)
RETURNS DECIMAL (18,2) AS
BEGIN
 DECLARE @dResult AS DECIMAL (18,2)
 IF @GUIDDecimal IS NOT NULL
  SET @dResult = ABS(CAST(CAST(@GUID AS VARBINARY) AS INT) % (@MaxValue-@MinValue + 1)) + @MinValue + ABS(CAST(CAST(@GUIDDecimal AS VARBINARY) AS INT) % 100)/100.0
 ELSE
  SET @dResult = ABS(CAST(CAST(@GUID AS VARBINARY) AS INT) % (@MaxValue-@MinValue + 1)) + @MinValue

 RETURN @dResult

END

Usage:

SELECT dbo.GetRandomDecimal(NewID(),100,500,NewID()) FROM TableA
– Return random decimal number from 100.00 to 500.99 as per row basis

Visual Round Trip Analyzer – VRTA


I come across this tool from my colleague. It is pretty interesting especially for public internet site or intranet site operating over low bandwidth.

“The Visual Round Trip Analyzer tool helps web developers and testers visualize the download of their page, identify best practices and changes that improve web performance. The network Round-Trip between the client and server(s) is the single biggest impact to web page performance – much greater than server response time. VRTA examines the communications protocol, identifying the causes of excessive round-trips, and recommending solutions. Performance engineers, testers, developers, operations personnel should use VRTA to conduct their web performance analysis”

Download here: http://www.microsoft.com/downloads/details.aspx?FamilyID=119F3477-DCED-41E3-A0E7-D8B5CAE893A3&displaylang=en

This installation required MS Network Monitor 3.2 to capture file for VRTA analysis. (http://www.microsoft.com/downloads/details.aspx?FamilyID=f4db40af-1e08-4a21-a26b-ec2f4dc4190d&displaylang=en)

Here are some screens previews after do some testing on www.bronios.com.


It provides detail performance analysis and overall score rating. The results are more comprehensive compare to firebug in Mozilla FireFox. My www.bronios.com seems get pretty bad rating. Time to change hosting company? :P

Web part updatepanel not working in publishing portal – ASP.NET AJAX and SharePoint


Today, I manage to solve this problem after spending hours of googling. During the integration between ASP.NET AJAX and SharePoint, you might found that AJAX does not working in certain type of SharePoint site template.

First, AJAX does not work in publishing site without doing some modification on the master page. It works in other site template such team site. The problem is that, the webpart manager TAG inside the master page“<WebPartPages:SPWebPartManager runat=”server”/>” has been placed before the Form Tag. To resolve this issue, just cut it and paste after the Form Tag as below

Original Code
<body class=”body” onload=”_spBodyOnLoadWrapper();”>
<WebPartPages:SPWebPartManager runat=”server”/>
<form runat=”server” onsubmit=”return _spFormOnSubmitWrapper();”>

….
….
Resolved Code
<body class=”body” onload=”javascript:if (typeof(_spBodyOnLoadWrapper) != ‘undefined’) _spBodyOnLoadWrapper();”>
<form runat=”server” onsubmit=”return _spFormOnSubmitWrapper();”>
<asp:ScriptManager runat=”server” ID=”ScriptManager1″></asp:ScriptManager>
<WebPartPages:SPWebPartManager runat=”server”/>

….
….

* You might found the similar solution in other place. I do a summary and make it easier to search by users with the correct keywords.

Error while writing managed code for infopath 2007 forms – InfoPath cannot add the event handler.


I receive some problem from my colleague when designing an infopath-2007 form that uses managed code for custom event handling. Here is the error:

InfoPath cannot add the event handler.

To work with Visual Basic or C# code, Microsoft visual studio tools for Applications (VSTA) is reguired. The Microsoft .Net Framework 2.0 and Microsoft Core XML Services 6.0 must be installed prior to installing VSTA…..

He has installed everything that is required. (MSXML Parser 6.0 / VS-2005 / VSTA) but still facing this error. Here is the solution from “Faithful”:
Read the rest of this entry »

RADEditor Permission denied issue.


I recently got chance to work on RadEditor control. It works fine in my local development environment. However, where I try to deploy the my application in to win2003 server. It give me permission error. Here are the details error happened to me.

1. Show page not found

2. Show 400 Bad request

3. Show permission denied

4. Debug the javascript and getting permission denied error.

Appreciate if anyone come across the same issue and point out the hints!

Update 2 June 2008

- I found that there my master page contains some CSS that cause the error:

<!–[if IE]>
<style type=”text/css” media=”screen”>
#menu ul li {float: left; width: 100%;}
body {
behavior: url(<http://www.mysite.com/css/csshover2.htc);
font-size: 100%;
}
</style>
<![endif]–>

This also explain why it only happen in IE browser. But the funny thing is this simple script can cause radEditor become malfunction and it only happen in certain conditions.

Posted in .Net. No Comments »

Error Installing the Session State Database


I am trying to setup SQL Session State database but encountered error as below:

An error occurred during the execution of the SQL file ‘InstallSqlState.sql’. The SQL error number is 229 and the SqlException message is: EXECUTE permission denied on object ‘sp_delete_job’, database ‘msdb’, schema ‘dbo’.If the job does not exist, an error from msdb.dbo.sp_delete_job is expected.
SQL Server: sql2005.valuethai.com
Database: [vtdb_ss]
SQL file loaded:
InstallSqlState.sql
Commands failed:…

Here is the command run by me:
aspnet_regsql.exe -S [sqlservername] -U [userid] -P [userpassword] -ssadd -sstype c -d [customdatabase]

After doing some debugging, I manage to solve it by assigning enough rights to msdb database. Once I map msdb to db_owner/public, it works fine.

Possible MOSS 2007 bug in content query web part?


Moss content query web part bugOne of my colleague found out one funny bug in moss 2007. Here are the steps to reproduce it:

  1. Add the content query web part, set to query items from page libraries from the whole site collection. (this should be default).
  2. Add filter on “Scheduling End Date” and set to a specific date
  3. Apply the setting and close the web part properties pane
  4. Open back the properties pane, settings for the date are gone, and went back to [Today]. 

This seems like a bug in MOSS 2007.  The bug still exist after install SP1. Do let me know if anybody out there having the same problem and solutions.

p/s: My colleague already contacted a MS guy in my region. I will update this blog once got any feedback from them.

MOSS Start Service Error: An unhandled exception occurred in the user interface.Exception Information: OSearch (Administrator)


This is a common mistake when try to start a MOSS search services:

An unhandled exception occurred in the user interface.Exception Information: OSearch (Administrator)

This error occur when you do not specific the machinename in your username. you must put in fulll name. e.g. mossadministrator.

MOSS Setup error: This product requires ASP.NET v2.0 to be set to ‘Allow’ in the list of Internet Information Services (IIS) Web Server Extensions.


If you ever get this error during moss or wss 3.0 installation, you can follow the step below to fix it.

Setup is unable to proceed due to the following error(s):
This product requires ASP.NET v2.0 to be set to ‘Allow’ in the list of Internet Information Services (IIS) Web Server Extensions. If it is not available in the list, reinstall ASP.Net v2.0.
Correct the issue(s) listed above and re-run setup.

Steps

1.  Run aspnet_regiis -i at .NET 2.0 folder.

2. If the error still exist, you need to manual “Allow” the asp.net 2.0 in IIS Web Server Extensions. 

Set ASP.NET v2.0 to be ‘Allow’ in the list of IIS Web Server Extensions

Disable right click on SQL reporting services report in SharePoint 2007


We are working on SharePoint Workspace with Business Intelligence solution. There some report build with reporting services show in SharePoint page. Then, we come across a special requirement that the client do not allow user to “Right click” on the entire SharePoint page including the reports. If you are using page viewer or report web part to view the report in native mode, you will never able to include your JavaScript to disable the right click. This is because it using iFrame to link to the report. To overcome this problem, there are 3 steps need to be done.

  1. Install and configure Reporting Services Add-in for SharePoint
    First, we need to install the “Microsoft SQL Server 2005 Reporting Services Add-in for Microsoft SharePoint Technologies” add-in and change reporting services to SharePoint integration mode. You can download the add-in in https://www.microsoft.com/downloads/details.aspx?familyid=1E53F882-0C16-4847-B331-132274AE8C84&displaylang=en  and get some introduction on its benefit here http://blogs.msdn.com/SharePoint/archive/2007/02/19/microsoft-sql-server-2005-sp2-reporting-services-integration-with-wss-3-0-and-moss-2007.aspx . You need to configure the reporting services after installed the add-in. You can easily find some help via google. Once done, you have to upload some report to SharePoint document library.
  2. Add JavaScript to disable the right click on SharePoint.
    To simplify the story, we use Content Editor Web Part to ad in the JavaScript. Enter code below in “Source Editor”:
    <SCRIPT language=”JavaScript” >
    function queryString(parameter) {
      var loc = location.search.substring(1, location.search.length);
      var param_value = false;
      var params = loc.split(“&”);
      for (i=0; i<params.length;i++) {
          param_name = params[i].substring(0,params[i].indexOf(‘=’));
          if (param_name == parameter) {
              param_value = params[i].substring(params[i].indexOf(‘=’)+1)
          }
      }
      if (param_value) {
          return param_value;
      }
      else {
          return false; //Here determine return if no parameter is found
      }
    }
    function right(e) {
    if (navigator.appName == ‘Netscape’ &&
    (e.which == 3 || e.which == 2))
    return false;
    else if (navigator.appName == ‘Microsoft Internet Explorer’ &&
    (event.button == 2 || event.button == 3)) {
    alert(“Sorry, you do not have permission to right click.”);
    return false;
    }
    return true;
    }
    document.onmousedown=right;
    document.onmouseup=right;
    if (document.layers) window.captureEvents(Event.MOUSEDOWN);
    if (document.layers) window.captureEvents(Event.MOUSEUP);
    window.onmousedown=right;
    window.onmouseup=right;
    </script>
    addin01.jpg
    The right click will disable on the specify page now.
    Read the rest of this entry »