Search This Blog

Wednesday, December 31, 2008

Happy New Year 2009!

Happy New Year 2009! may better year ahead.

Wednesday, December 24, 2008

Merry Christmas!!!!

Wish you all merry christmas!!!!!!!!!!!!

Tuesday, December 16, 2008

Lock Windows XP

Sometimes, we need to lock our windows XP when we go out for a walk or leave our computer for a while in order to protect our information from others. Normally, pre install windows xp wont have the button/menu for us to lock it.

Here are few steps we can do to lock out computer.
  1. Go to Desktop, use your mouse right click on your desktop and select "New/Shortcut" from the list



  2. Once done, copy and paste the command rundll32.exe user32.dll, LockWorkStation and click "Next"



  3. Give a name to your shortcut before choosing the "Finish" option

Done.

Monday, December 15, 2008

Local Folders have xx new messages

Yes, i receive this message in taskbar but i cannot find any new email in my Local Folders .. strange.

After check on MozillaZine Knowledge Base. I found out that there is one setting that i left out and cause this issue:

My scenarion: I'm using pop mail.

To solve it, go to Tools --> Account Settings ...



Expend the account. Click on Server Settings. Checked/Select Automatically download new messages.




Now i can see my email after receive alert that "Local Folders has 1 new message".

Problem solved!

Sunday, December 14, 2008

SQL Server 2005 Developer Edition at USD49.95




Yes, this is true. Only USD49.95!



Overview for SQL Server 2005 Developer Edition: SQL Server 2005 Developer Edition provides a complete set of enterprise data management and business intelligence features. Because—like Enterprise Edition—it is optimized to run on x64 and Itanium-based servers, it is the most scalable and available edition of SQL Server 2005.

Check out in microsoft store.

Friday, December 12, 2008

AJAX PHP CAPTCHA

Thanks for http://www.phpcaptcha.org/documentation/quickstart/ provide a cool php captcha code. One of my colleague supporting a php site which need CAPTCHA to prevent spamming but most of the example given needed page post back which is not so practical. I have implement an AJAX CAPTCHA for ASP in my previous post on AJAX ASP CAPTCHA.

Now, we are using the same method to implement in PHP. By reuse the same javascript code with jquery, there is only a small changes in PHP part. Within 20 minutes, the code done and tested working. The files available for download here.

Happy programming. Please let me know if you have any problem.

Sunday, November 30, 2008

Dell Latitude E6400



I have been DELL Latitude fans since i work in DELL early 2004. My first test out was DELL Latitude D600, the following DELL notebook was DELL Latitude D800 and DELL Latitude D620. You may wonder why DELL specifically Latitude

I can give you some reasons:

  1. The price: it's not too expensive, it's slightly higher than getting a DELL Vostro or DELL Studio. Normally my machine cost is about RM4K - 6K (USD 1.3K - 1.8K)
  2. The outlook: it's always have cool looking (I'm mention DELL Latitude series, not Inspiron or Vostro). It looks quite elegant with this price.
  3. The performance: it perform very well, i heavyly use my notebook for programming (.NET, MSSQL, C++), debugging and etc. It still can meet my requirement. My battery can last for 4 hours without charging. This is important for me when meeting customer in cafe and etc.
  4. The warranty services: this is what i love most but it depend on your warranty that you purchase. I've my next business day warranty service. I call it today, the next day i'll get the warranty parts and the engineer with come to change the part for you without any further questions. Remember to get your warranty service whenever you purchase your notebook. It's important.





My new DELL Latitude E6400 specs:


  1. Intel(R) Core(TM)2 Duo Processor P8400

  2. 3 Yrs Next Business Day Onsite Service

  3. 3Yr CompleteCover

  4. Dell Wireless 370 Bluetooth(R) 2.1

  5. Intel WiFi Link 5300 (802.11 a/g/n 3X3) MiniCard

  6. 4GB (2x2GB) 800MHz DDR2 SDRAM

  7. 250GB SATA (5400RPM) Hard Drive

  8. Genuine Windows(R) XP Professional SP3 -Downgrade Vista Business Basic(EMRP)

  9. 14.1" Widescreen WXGA (1280x800) Display

  10. Integrated 10/100/1000 Ethernet

  11. High Definition Audio Codec

  12. 5-in-1 Media Card Reader

  13. 8X DVD+/-RW Drive

  14. Mobile Intel(R) Graphics Media Accelerator X4500HD With Express Card

  15. Power DVD Software and Media CD

  16. 56k Internal Modem

  17. 6-Cell Li-Ion Primary Battery

  18. 90W AC Adapter

Dell latitude E6400 come with a very cool notebook messenger bag. Light and slim. I bet you will love it.




Tuesday, November 18, 2008

Classic ASP CAPTCHA with JQuery Cross domain AJAX

It come to the point that i need to maintain my old application which written in ASP. I was asked to add a new feature in form submission to prevent from spamming. CAPTCHA is the thing that i could thought of. Thanks Emir Tüzül who willing to share his ASP CAPTCHA. You can download it from http://www.tipstricks.org/ .

I downloaded the code and modify the code so that the security checking is before the asp postback. The solution i could thought of is AJAX. When i thought of javascript, the coolest javascript framework will be JQuery.

The decision is go for JQuery in order to perform Ajax with ASP.

There is one concern, the application will need to perform cross domain ajax. If use normal jquery ajax (code below), it will work if all the file reside in the same domain but not when cross domain. Error : Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "" data: no] will be displayed.

var html = $.ajax({
url: "/captcha.asp?validateCaptchaCode=" + $("#captchacode").val(),
async: false
}).responseText;

In our case, the file put in different domain. The technics will be use is Cross-Domain getJSON (using JSONP). Sample code below

$.getJSON("captcha.asp?validateCaptchaCode=" + $("#captchacode").val() + "&format=json&jsoncallback=?", function(data)
{
if (data.status == "1")
{ alert("verified and submit.");
$("#form").submit();
result = true;
}
else
{
if (data.session == "0")
RefreshImage("imgCaptcha");
alert("Please key in the security key correctly!");
$("#captchacode").focus();
result = false;
}
});


The Cross-Domain getJSON will espect the data return in Json format. So, my ajax handler file (in my case is captcha.asp) will need to return Json format data for processing.

After develop and tested. It's work. You can download my sample file here and test on it. Please let me know if it's help.

Sunday, November 16, 2008

screnc.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

I get below error message when try to encrypt my asp file.

"screnc.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

In my old machine, everything is working fine (xp pro sp2) but when come to new machine (xp pro sp3), problem occur. Acording to this article, there is no way can be done in xp sp3 unless we install a virtual machine to run it. So, i give up on running this in my new machine.

End up, i run it in my dedicated server which give me cool output file.

IE 7 hang when close the browser

My IE7 will hang most of the time when i try to close it if i open many tab or windows. End up, i need to hit Ctrl, Alt, delete to close it.

My machine spec:
  • XP pro SP3
  • Intel Core 2 Duo P8400 @ 2.26GHz 791 MHz
  • 4GB RAM

It shouldn't hang with my machine spec.
Many article suggest that it's caused by the IE Add-ons. So, i try my luck to disable the Add-ons one by one.

Finally, i found that after i disable Skype Add-ons, my problem solved.
To Enable/Disable IE Add-ons,
  1. Open IE
  2. Click on Tools, click on Manage Add-ons -> Enable or Disable Add-ons asd
  3. Manage Add-ons windows will be pop up.
  4. Select the add-ons you want to disable.
  5. Click OK to close the windows
  6. Close all the IE and start again.
Now my IE is working fine. Hope this solve your problem.
UPDATE: it solve my problem for only a day. Problem come back the next day.
The real action that solve my problem is uninstall google toolbar which is my last choice. Hope this solve your problem.
UPDATE: 10/12/2008. My problem confirm solved after uninstall google toolbar.

Tuesday, November 11, 2008

Database diagram support objects cannot be installed because this database does not have a valid owner.

I have restore a database from MSSQL 2000 to MSSQL 2005. When i try to open the database diagram, error message below pop up:

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.

ALTER AUTHORIZATION ON DATABASE: Database_name TO valid_login

I use SSMS to solve my problem.
In SQL Server Management Studio do the following:
  1. Right Click on your database, choose properties
  2. Go to the Options
  3. In the Dropdown at right labeled "Compatibility Level" choose "SQL Server 2005(90)"
  4. Go to Files
  5. Type "sa" in the owner textbox
  6. Click OK
This solve my problem.

Alternatively, we can solve it using TSQL:
- My database name: avlDB
- MY Login: sa

EXEC sp_dbcmptlevel 'avlDB', '90';
GO
ALTER AUTHORIZATION ON DATABASE::avlDB TO "sa"

GO
USE [avlDB]
GO
EXECUTE AS USER = N'dbo' REVERT
GO

Monday, November 10, 2008

The memory could not be written

After i change My Computer name, my machine (Windows XP Pro SP3) getting very very slow and hit below message when try to install some simple application and even hit the same error notepad.

"The instruction at "0×62e2cc0f" referenced memory at "000000000". The memory could not be written. "

Try to work around and suft here and there but not able to find any solution.

Finally System Restore work for me.

To use System Restore to restore Windows XP to a previous state, follow these steps:

  1. Log on to Windows as Administrator.
  2. Click Start, point to All Programs, point to Accessories, point to System Tools, and then click System Restore. System Restore starts.
  3. On the Welcome to System Restore page, click Restore my computer to an earlier time (if it is not already selected), and then click Next.
  4. On the Select a Restore Point page, click the most recent system restore point in the On this list, click a restore point list, and then click Next.
    Note A System Restore message may appear that lists configuration changes that System Restore will make. Click OK.
  5. On the Confirm Restore Point Selection page, click Next. System Restore restores the previous Windows XP configuration, and then restarts the computer.
  6. Log on to the computer as Administrator. The System Restore Restoration Complete page is displayed.
  7. Click OK.
For more information, please visit http://support.microsoft.com/kb/306084

Friday, November 7, 2008

SQL Server Setup failed to obtain system account information for the ASPNET

Trying to setup MSSQL 2005 Developer version in my new machine OS Windows XP Profesional SP3, when come to installation point, error message below appear:

"SQL Server Setup failed to obtain system account information for the ASPNET account. To proceed, reinstall the .NET framework, and then run SQL Server Setup again"

Under Add/Remove Programs, i have Framework 1.1, 2.0 and 3.0 installed.

What next? After surf around, here is the solution:

Steps:

1. Click on Start -> Run






2. Type in cmd and click OK





3. Command prompt screen will appear. go to"C:\Windows\Microsoft.NET\Framework\v1.1.4322" folder by using command cd C:\Windows\Microsoft.NET\Framework\v1.1.4322 and hit enter. Please refer screen below:





4. Type in aspnet_regiis -i and hit enter.




5. Screen below will be shown and dotnet user installed.




Try to install MSSQL 2005 again. It's work.


Problem solved.





Wednesday, October 8, 2008

SQL server remap user - blank Login name

i come across this situation: my customer backup a db and i restore in our development server. The login user have empty "Login name". Hence, i'm not able to connect using this user name.



finally, i found out that we can use sp_change_users_login to map with login name.

for my case, my database name is HHotel, user login will be 'lam' and password 'l!a2m#'

USE HHotel;
GO
EXEC sp_change_users_login 'Auto_Fix', 'lam', NULL, 'l!a2m#';
GO

It's fixed after run above script.

For more example: http://msdn.microsoft.com/en-us/library/ms174378.aspx

Saturday, September 27, 2008

Friday, September 19, 2008

Remove Messenger (MSN or Yahoo) advertisement

I have applied a patch that able to remove the annoying advertisement for MSN Messenger. The patch not only able to remove the advertisement but many others [features] that come with the messenger.

My MSN Messenger is Version 2008 (Build 8.5.xxxxx). Go to http://apatch.org/downloads.php and download A-Patch for Windows Live Messenger 8.5. Extract the zip file and run the .exe file. No worry, it's safe. This is a cool patch with preview feature during the selection of unwanted feature. Try it.

Wednesday, September 17, 2008

DllRegisterServer failed with error code 0x80004005 ...

I was trying to register a dll with command prompt in Vista but error message prompt ".. DllRegisterServer failed with error code 0x80004005 ...."



finally i found out that is because of security issue. To solve this,
Go to Start --> All Programs --> Accessories, right-click Command Prompt, and then click Run as Administrator

Then use regsvr32 to register the DLL.

It's work.

Tuesday, September 16, 2008

Automate SQL 2005 Express Database backup

I just want to share a very cool SQL Agent that allowed us to automate the database backup by simple setting. Thanks to the author Danilo Corallo for sharing and make life our easier.







Sunday, September 14, 2008

osticket - admin login error "Authentication Required"

i have tried to setup osticket few times and i'm very sure that my admin username and password is correct but i still got error message "Authentication Required"

After browse and google around, i found one solution to enable me to login but i'm not sure what is the effact for this change.

go to scp/staff.inc.php, and find the line below

//1) is the user Logged in for real && is staff.
if(!is_object($thisuser) !$thisuser->getId() !$thisuser->isValid()){

comment out !$thisuser->isValid() and now become

if(!is_object($thisuser) !$thisuser->getId() /* !$thisuser->isValid()*/){

go to try again. it's working. Perhap, someone can tell me what is the issue and i'm not php expert. Not working on 15 Sep 2008

Update: 15 Sep 2008
No Luck. It only work for one day. Not sure what happen and now not working. I'll keep updating this post until get some solution or work around. I have to un comment previous changes.

Solution:
line 41 in scp\login.php, comment out @header("Location: $dest"); and try again.
// @header("Location: $dest");
it's work for me, at least for now.

Update: 21 Sep 2008
It's working fine since changes on 15 Sep 2008. SOLVED!

The user instance login flag is not supported on this version of SQL Server. The connection will be closed.

I have download an open source asp.net app. The database supported is SQL Express. When i try to run the app, error message [The user instance login flag is not supported on this version of SQL Server. The connection will be closed. ].

The reason is my installed database is full version of mssql 2005 and not express version. In order to make it run in my development machine, i have change the connectionstring in tag
<connectionstrings> from


<add name="TDConnectionString" connectionString="data source=.\SQLExpress;Integrated Security=SSPI;AttachDBFilename=DataDirectoryTD.mdf;User Instance=true"
providerName="System.Data.SqlClient" />

to


<add name="TDConnectionString"
connectionString="server=.\SQLSERVER2005;database=TD;uid=xxx;pwd=xxxxx"
providerName="System.Data.SqlClient" />

where ".\SQLSERVER2005" is my database server.

It's works now.

Monday, September 8, 2008

Call VBScript in Javascript

Well, it's actually working fine in IE but not other browser. As we all know, client side vbscript is microsoft product and it's only support in IE.

Try this,

<HTML>
<HEAD>

<SCRIPT LANGUAGE=vbscript>
Function vbFunc()
Msgbox("VBScript: Vb function")
End Function

</SCRIPT>

<SCRIPT LANGUAGE=javascript>

function jsFunc()
{
alert("Javascript: jsFunc function");
vbFunc();
}

</SCRIPT>

</HEAD>
<BODY onload="jsFunc()" >
</BODY>
</HTML>

Sunday, September 7, 2008

Streamyx with D-Link 2640T Wireless ADSL Router

Just test on streamyx connection with D-Link 2640T Wireless ADSL Router.





For streamyx setting:
  1. Open your internet browser and go to http://192.168.1.1/, default user name/password: admin/admin
  2. Click on wizard to run the setting. Click next to begin.
  3. 1st setting will be "Choose Time Zone", select the one relavent to your time zone. For me, i select [(GMT+08:00) Hong Kong,Perth,Singapore,Taipei] since there is no Kuala Lumpur. Click on Next.
  4. 2nd setting will be "Select Internet Connection Type (WAN)". For streamyx i select PPPoE/PPPoA and click next.
  5. 3rd setting is "Set PPPoE / PPPoA". For steamyx user, keyin your user name and password.
    User Name: xxx@streamyx
    Password: xxxxxxxx
    VPI: 0 ---- 8 wont work for me, the status is waiting for response if i choose VPI: 8
    VCI: 35
    Connection Type: PPPOE LLC
  6. 4th setting is "Set Wireless LAN Connection". This is up to user to set on it. Read the menu correctly.
  7. Save and restart your router. The status should be "connected" if you check the status tab.





Happy surfing!

Sunday, August 17, 2008

Thank You

Thanks For your support!

TextArea Newline

Even wonder how to construct a new in TextArea? Many try to use <BR>
and /n but both doestn't work for me. But this &#10; work for me. Forget to mention, i'm using IE7 when do the testing. I'm not sure whether this is browser dependent.

Tuesday, August 12, 2008

ASP.NET: colon in querystring cause error "is not a valid virtual path."

Server Error in '/' Application.
'~/Search.aspx?pageidx=1&Id=:' is not a valid virtual path.


Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: '~/Search.aspx?pageidx=1&Id=:' is not a valid virtual path.


Understand that in asp.net, virtual path in the URL with colon (:) is not allowed. To solve this problem, i replace the colon (:) with ASCII value for colon &#58; (please check http://www.asciitable.com/) and HttpUtility.UrlEncode on the search key before pass into search.aspx as querystring.

In Search.aspx.cs, do HttpUtility.UrlDecode and pass to DB for searching purposes. Problem solve. Bear in mind that you might need to disable the ValidateRequest (ValidateRequest="false") which may open for dangerous hijack/request.

Monday, August 11, 2008

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Server Error in '/xxxxx' Application.

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.            

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the
error and where it originated in the code.

Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

Line 89: <%# if (Eval("UserId").ToString().Length != 0) {%>


googling around and not able to find a solution. What i do is i put the if/else condition into a function and pass in UserId as parameter and output the desire output string.

now my line 89: become <%# FormatRatedDisplay(Eval("UserId").ToString())%> and new function FormatRatedDisplay will return a string. I issue solved.

Thursday, August 7, 2008

Microsoft .Net Framework TPM - Virus

My antivirus detect a new virus and some file has been deleted but there is a pop up windows keep on showing up and say that "procedure not found". After check around, i found something strange in windows services

Service name: bjvhrz
Display name: bjvhrz
Description: Microsoft .NET Framework TPM
Path to executable: C:\WINDOWS\system32\svchost.exe -k bjvhrz



I'm not able to stop and to disabled it.



To solve it,
  1. Disable System Restore
  2. Back up registry
  3. Restart in Safe Mode
  4. Open Registry Editor. Click Start>Run, type REGEDIT, then press Enter.
  5. In the left panel, double-click the following:
    HKEY_LOCAL_MACHINE>SYSTEM>CurrentControlSet>Services
  6. Still in the left panel, locate and delete the key:
    bjvhrz
  7. Close Registry Editor.

Thursday, July 24, 2008

'HTTP 405 - Resource Not Allowed' in asp

I hit error message 'HTTP 405 - Resource Not Allowed' when trying code below.


sQueryString = Request.Querystring

sUrl = "http://www.xxx.com/index.htm?" & sQueryString

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", sUrl, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send fContent
Response.write xmlhttp.responseText
set xmlhttp = nothing


After debugging, just found out that we are not allow to do post method on a static web "htm" or "html".

Change sUrl = "http://www.xxx.com/index.htm?" & sQueryString to sUrl = "http://www.xxx.com/index.asp?" & sQueryString solve the problem. Of course the file should be exists.

Wednesday, July 9, 2008

Javascript: Shorten for if/else

Sometime our code will looks messy if containing too many if/else. We can shorten the code and make it more tidy. Check the code below:

<html>
<head>
<script language="JavaScript">
function foo()
{
var myGender = "female";
alert((myGender == "male") ? "i am male" : "I am female");
}
</script>
</head>
<body onload="javascript:foo();">
</body>
</html>

Monday, July 7, 2008

Retrieve data from DataTable

I have a DataTable that containing set of data. To get only column name "score" from the DataTable called MyDataTable. Below is how i do

for (int i = 0; i < MyDataTable.Rows.Count; i++)

{

string score = MyDataTable.Rows[i]["score"].ToString();

xxxxxx

xxxxxx

}

Thursday, July 3, 2008

W3SVC Restart when changing ASP.NET version in ASP.NET tab (IIS)

I'm not sure what is happening but i suspect that i change the ASP.NET version in IIS cause W3SVC restart. All application in the same application pool working ok and restart successfully but other application pull have some issue.

If anyone face the same or similar issue, maybe can share your solution.

Zip & FTP database for backup purposes

My situation:

i need to backup, zip and FTP my database to another server for safety purposes.

My MSSQL database run a daily backup job at 12:00AM to backup folder (E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\) with name: MyDB_backup_200806010000.bak
where 2008 = YYYY, 06 = MM, 01 = DD and 0000 is fixed

my part is zip MyDB_backup_200806010000.bak to MyDB_backup_200806010000.zip and FTP to folder myapp/db in the remote site.

Software: 7zip, core ftp LE (both are free), both can be downloaded free only, google it online and you can get the file downloaded.

Steps:
1. Install Core Ftp LE in the server (my installation folder: c:"\program files\coreftp\coreftp.exe")
2. Open Core Ftp LE and create my FTP site and enter FTP username and password. I name my site mybacksite.
3. Install 7zip in the server. Copy 7z.exe from the installation folder (mine is in C:\Program Files\7-Zip\7z.exe) to database backup folder (mine is in E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\).
4. Write a windows batch script (batch) to perform the zip and ftp process. I name it appDBbackup.bat and put it in (mine is in E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\)

appDBbackup.bat:

@echo Off

for /f "tokens=1,2" %%u in ('date /t') do set d=%%v

for /f "tokens=1" %%u in ('time /t') do set t=%%u

if "%t:~1,1%"==":" set t=0%t%

rem set timestr=%d:~6,4%%d:~3,2%%d:~0,2%%t:~0,2%%t:~3,2%

set datestr=%d:~6,4%%d:~0,2%%d:~3,2%

set timestr=%t:~0,2%%t:~3,2%

7z a -tzip MyDB_backup_%datestr00.zip MyDB_backup_%datestr00.bak

setlocal

c:"\program files\coreftp\coreftp.exe" -s -O -u "E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\MyDB_backup_%datestr00.zip" -site mybacksite -p /myapp/db/


5. Create a windows scheduler to run the job. Point the task to appDBbackup.bat. In my case, i point to E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\appDBbackup.bat and i schedule it at 12:30AM, 30 minutes after the backup started.



to know more on how to create windows scheduler. read this

Done.

Monday, June 30, 2008

C# String.Format - Input string was not in a correct format Error

Error message: Input string was not in a correct format Error when i try to use String.Format in C#.

below are the code that have problem

info = string.Format("{\"name\":\"{0}\",\"img\":\"{1}\",\"href\":\"{2}\"}", Username, PhotoUrl, UserId);

try to figure out here and there and finally found the problem and solution. It's caused by both { and }.

To solve this problem, change
{ to {{ and } to }}. It will become

info = string.Format("{{\"name\":\"{0}\",\"img\":\"{1}\",\"href\":\"{2}\"}}", Username, PhotoUrl, UserId);

problem solved!

Friday, June 27, 2008

JQuery document ready

If you want to fire an event after the document ready using jquery, you can call function inside $(document).ready(function()){// put all jQuery function here}); or $(function() {// put all jQuery function here.});

You can use
  1. $(document).ready(function() {
  2. // put all jQuery code in here.
  3. });
or
  1. $(function() {
  2. // put all jQuery code in here.
  3. });

Thursday, June 19, 2008

Google Toolbar for Firefox 3

Google have release Google Toolbar for firefox 3, the Toolbar can be downloaded from http://www.google.com/tools/firefox/toolbar/FT3/intl/en/index.html

Saturday, June 14, 2008

Google adsense in between blog in blogger (blogspot)

Below picture show adsense display in between blog. How to create absense in between blog in blogger?



steps:
  1. Login into blogger,
  2. Click on Layout
  3. Click on Edit HTML
  4. Click on Expand Widget Templates




Search the word "post-footer-line post-footer-line-3"

put you adsense before the tag
<div class='post-footer-line post-footer-line-3'/>

example:

..................................................
.................................................
<div>
<script type='text/javascript'>
google_ad_client = "pub-3954566333638548";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al";
//2007-10-13: dotnetfish.blogspot.com
google_ad_channel = "8291285977";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0066CC";
google_color_text = "000000";
google_color_url = "0066CC";
</script>
<script src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript'>
</script>
</div>
<div class='post-footer-line post-footer-line-3'/>
......................................
......................................

Done

Microsoft Surface SDK

Microsoft Surface team have not official release public Surface SDK but there is demo in action.


Understand from surface team that there will be two layers, that are Core & WPF. The Core layer supports any .NET UI framework. The WPF layer provides the same functionality as the Core layer and also highly consistent with WPF’s model for input & controls.

Thursday, June 12, 2008

textContent not working in IE, use innerHTML

My javascript is working fine in FireFox and Safari but when use IE (mine is IE7), it's give me problem [Undefined].

.........................
..........................
this.post[i].head = this.posts[i].getElementsByTagName('a')[0];
this.post[i].title = this.post[i].head.textContent;
.......................
......................

Spend hours to check on the issue and finally found a very simple way to solve it, use innerHTML instead of using textContent.

.........................
..........................
this.post[i].head = this.posts[i].getElementsByTagName('a')[0];
this.post[i].title = this.post[i].head.innerHTML;
.......................
......................


problem solve.

Tuesday, June 10, 2008

Result

Monday, June 9, 2008

Internet Explorer cannot open the Internet site http://mail.google.com/mail/. Operation aborted

Recently upgrade to IE7 from IE6. When i try to logon to my Gmail, error message below shown


Internet Explorer cannot open the Internet site http://mail.google.com/mail/


Operation aborted

IE7 is one of the gmail supported browser. http://mail.google.com/support/bin/answer.py?hl=en&answer=6557

I've tried to delete the browser's cookies. It work for me at least until now (2 days) but some of my friend not working. One of the way that always work for me is click on the gmail button from google toolbar.

Official solution from Google:
http://mail.google.com/support/bin/static.py?page=known_issues.cs&knownissue=gmail_issue_ie7operationaborted&topic=12778

Sunday, June 8, 2008

[Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e

facing problem [Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "" data: no] .


This is cause by calling AJAX file different domain from my current site.Check my previous post

http://dotnetfish.blogspot.com/2007/11/jquery-exception-permission-denied-to.html


Tuesday, May 27, 2008

Searching word in Stored Procedure

Sometime it's very useful if we can search word in Stored Procedure for debugging purposes or etc. Use below script to search with stored procedure using table called "tblLookup"

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%tblLookup%'
AND ROUTINE_TYPE='PROCEDURE'
ORDER BY ROUTINE_NAME ASC

Friday, May 2, 2008

64-bit or 32-bit / x64 or x84

It's always come to the point that we need to know our system is 64-bit or 32-bit / x64 or x84 when we download some installer or choose installation option.

Below is how we determine 64-bit or 32-bit / x64 or x84 for different windows OS.

Windows Vista

Method 1
1.Click Start, type system in the Start Search box, and then click system in the Programs list.
2.The operating system appears as follows:
• For a 64-bit version operating system: 64-bit Operating System appears for the System type under System.
• For a 32-bit version operating system: 32-bit Operating System appears for the System type under System.

Method 2
1.Click Start, type system in the Start Search box, and then click System Information in the Programs list.
2.The operating system appears as follows:
• For a 64-bit version operating system: x64-based PC appears for the System type under Item.
• For a 32-bit version operating system: x86-based PC appears for the System type under Item.

Microsoft Windows XP Professional

Method 1
1.Click Start, click Run, type sysdm.cpl, and then click OK.
2.Click the General tab. The operating system appears as follows:
• For a 64-bit version operating system: Microsoft Windows XP Professional x64 Edition Version <year> appears under System.
• For a 32-bit version operating system: Microsoft Windows XP Professional Version <year> appears under System. Note is a placeholder for a year.

Method 2
1.Click Start, click Run, type winmsd.exe, and then click OK.
2.In the details pane, locate Processor under Item. Note the value.
• If the value that corresponds to Processor starts with x86, the computer is running a 32-bit version of the Windows operating system.
• If the value that corresponds to Processor starts with ia64 or AMD64, the computer is running a 64-bit version of the Windows operating system.

Microsoft Windows Server 2003

Method 1
Click Start, click Run, type sysdm.cpl, and then click OK.
Click the General tab. The operating system appears as follows:
• For a 64-bit version operating system: Microsoft Windows Server 2003 Enterprise x64 Edition appears under System.
• For a 32-bit version operating system: Microsoft Windows Server 2003 Enterprise Edition appears under System.

Method 2
1.Click Start, click Run, type winmsd.exe, and then click OK.
2.In the details pane, locate Processor under Item. Note the value.
• If the value that corresponds to Processor starts with x86, the computer is running a 32-bit version of the Windows operating system.
• If the value that corresponds to Processor starts with EM64T or ia64, the computer is running a 64-bit version of the Windows operating system.

reference: http://support.microsoft.com/kb/827218

Thursday, May 1, 2008

Invalid use of 'EXECUTE' within a function

I've tried to create a MSSQL "User Defined Functions" with execution of dynamic query (return a final value) and hit error message: "Invalid use of 'EXECUTE' within a function"

The reason is MSSQL not allow execution of dynamic query in "User Defined Functions". Because of this, i need to change from user "User Defined Functions" to "stored procedure" SP by using sp_executesql.

Below show example the Stored Procedure that i use to overcome my problem.

I need my SP to return a calculated value.

CREATE PROCEDURE dbo.psp_GetOCPrice
(
@strSKUNo VARCHAR(50),
@BOMT NUMERIC(9,2),
@OtherCharges NUMERIC(9,2) OUTPUT
)
AS
BEGIN

DECLARE @Count INT,
@Max INT,
@Cost NUMERIC(9,2),
@SQL NVARCHAR(4000),
@Formula NVARCHAR(1000),
@othMainIdn INT,
@othIdn INT


DECLARE @tblOthCharges TABLE
(
ID INT IDENTITY(1,1),
SKUNo VARCHAR(50),
othIdn INT,
othMainIdn INT,
Formula VARCHAR(1000),
Cost NUMERIC(9,2)
)

INSERT INTO @tblOthCharges(SKUNo, othIdn, othMainIdn, Formula)
SELECT sm.SKUNo, sm.pid, sm.ItemGroup,ISNULL(sm.Formula,0) Formula
FROM tblSKUMat sm
WHERE SKUNo = @strSKUNo
AND sm.othCharFlag = 1 ORDER BY sm.seqID ASC

SET @BOMT = ISNULL(@BOMT,0)

SET @Max = (SELECT COUNT(ID) FROM @tblOthCharges)

SET @Count = 1
SET @Cost = 0

SET @SQL = ''

SET @SQL = @SQL + ' DECLARE @BOM NUMERIC(9,2), ' + char(13)
SET @SQL = @SQL + ' @Cost NUMERIC(9,2) ' + char(13)
SET @SQL = @SQL + ' SET @BOM = ' + CONVERT(VARCHAR,@BOMT) + ' ' + char(13)
SET @SQL = @SQL + ' SET @rOtherCharges = 0 ' + char(13)

WHILE @Count <= @Max BEGIN SELECT @Formula = Formula, @othMainIdn = othMainIdn, @othIdn = othIdn FROM @tblOthCharges WHERE ID = @Count

SET @SQL = @SQL + ' SELECT @Cost = ' + CONVERT(VARCHAR,@Formula) + char(13)

SET @SQL = @SQL + ' DECLARE @v' + CONVERT(VARCHAR,@othMainIdn) + '_value NUMERIC(9,2) '


SET @SQL = @SQL
+ char(13)

SET @SQL = @SQL + ' SET @v' + CONVERT(VARCHAR,@othMainIdn) + '_value = ISNULL(@Cost,0) '

SET @SQL = @SQL
+ char(13)

SET @SQL = @SQL + ' SET @rOtherCharges = @rOtherCharges + ISNULL(@Cost,0) ' + char(13)

SET @Count = @Count + 1
END

DECLARE @ParmDefinition NVARCHAR(500);

SET @ParmDefinition = N'@rOtherCharges NUMERIC(9,2) OUTPUT';

EXECUTE sp_executesql
@SQL,
@ParmDefinition,
@rOtherCharges = @OtherCharges OUTPUT;

END

GO

i need to use dynamic query because the field "
Formula" is mathematics expression where involve calculation using value from parameter.
By using
sp_executesql, the value for @rOtherCharges will be assigned to @OtherCharges OUTPUT.

To call this SP, simply call execution

Declare
@OtherCharges
Execute dbo.psp_GetOCPrice 'XIN200805010001', 2000.20, @OtherCharges NUMERIC(9,2)

Done!



Wednesday, April 23, 2008

Create View using Stored Procedure dynamically

We can create view using stored procedure dynamically.

Please find my sample below:

I want to create a view name v_rpt + @Type and @Type as parameter. If the view already exists, it will be drop and recreate a new one.

We will need to execute @SQL twice

  • execution 1: check whether the view exists, drop it if exists
  • execution 2: create a new view
if we put both in the same query, it will hit error "'CREATE VIEW' must be the first statement in a query batch."


CREATE PROCEDURE [dbo].psp_Generate_view
(
@Type VARCHAR(255)
)
AS

BEGIN

SET NOCOUNT ON

DECLARE @SQL VARCHAR(8000)

SET @SQL = ''
SET @SQL = @SQL + 'IF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID(N''[dbo].[v_rpt' + CONVERT( VARCHAR, @Type) + ']'') AND OBJECTPROPERTY(id, N''IsView'') = 1) ' + char(13)
SET @SQL = @SQL + 'DROP VIEW [dbo].[v_rpt' + CONVERT( VARCHAR, @Type) + '] ' + char(13)

EXECUTE (@SQL)

SET @SQL = ''
SET @SQL = @SQL + 'CREATE VIEW dbo.v_rpt' + CONVERT( VARCHAR, @Type) + ' AS ' + char(13)
SET @SQL = @SQL + 'SELECT DISTINCT '
SET @SQL = @SQL + 's.SKUNo, '
SET @SQL = @SQL + 's.Model, '
SET @SQL = @SQL + 'lk1.LookupDesc [Region], '
SET @SQL = @SQL + 'lk2.LookupDesc [Country], '
SET @SQL = @SQL + 'CASE s.Status '
SET @SQL = @SQL + ' WHEN 1 THEN ''Saved'' '
SET @SQL = @SQL + ' WHEN 2 THEN ''Rejected'''
SET @SQL = @SQL + ' WHEN 3 THEN ''Approved'''
SET @SQL = @SQL + 'END AS Status, '
SET @SQL = @SQL + 's.Remark, '
SET @SQL = @SQL + 'u1.FullName [Creator], '
SET @SQL = @SQL + 's.CreDte [Date of Creation], '
SET @SQL = @SQL + 'u2.FullName [UpdatedBy], '
SET @SQL = @SQL + 's.LastUpdDte [Updated On], '
SET @SQL = @SQL + 'FROM tblSKU s '
SET @SQL = @SQL + 'LEFT OUTER JOIN tblUser u1 ON s.OwnerID = u1.UserID '
SET @SQL = @SQL + 'LEFT OUTER JOIN tblUser u2 ON s.LastUserID = u2.UserID '
SET @SQL = @SQL + 'LEFT OUTER JOIN tblLookup lk1 ON s.Region = lk1.RefIdn AND lk1.GroupIdn = 1 '
SET @SQL = @SQL + 'LEFT OUTER JOIN tblLookup lk2 ON s.CTY = lk2.RefIdn AND lk2.GroupIdn = 2 '
SET @SQL = @SQL + 'WHERE '
SET @SQL = @SQL + 's.Type= ' + CONVERT( VARCHAR, @Type) + ' AND '

EXECUTE (@SQL)


SET NOCOUNT OFF
END


Please let me know if you have any comment.

Tuesday, April 22, 2008

The worst wireless modem router that have ever used



Trust me, don't go to get Aztech modem. You will regrets if you have one.

Aztech DSL600EW ADSL2/2+ Ready Wireless LAN 802.11g is the worst modem that i ever had. The wireless line simply disconnected and need to restart the router, the ADSL frequently disconnected with the service provider, the stupid un-userfriendly interface (even a simple port forwarding takes me hour to configure and yet cannot be done). I bet you will definately throw it out from your house or office.

Saturday, April 19, 2008

VBScript: Open new windows (IE)

To open new window using client side vbscript,
use open "url", "target", "options"

example:

Sub fnOpenUrl(url)

open url ,"newWindow", "toolbar=no, menubar=no, status=no, width=830, height=660 titlebar=no, scrollbars=yes, resizable=yes, top=5, left=5 "

End Sub

to call the function

fnOpenUrl("http://www.xincrm.com")

Done.

Thursday, April 17, 2008

DefaultButton for ImageButton not working in firefox

Well, read this article first before finding other solution http://support.microsoft.com/kb/921277

I've been trying to look around and work on the code but it's not working. Don't waste your time for simple problem unless you have plenty of them.

The easiest way is change the ImageButton control to Button control as stated in the article. Put in some css will give the same effect/result in term of display like in ImageButton.

Below is the css that i use for this purposes.

.buttoncss
{
width:98px;
height:43px;
background-color:#FFFFFF;
background-image:url(http://xincrm.com/img/Button.gif);
border-style:none;
cursor:pointer;
}

Try this http://www.pagetutor.com/button_designer/index.html if you want to customize your button css. Very useful for me.

Remember set UseSubmitBehavior for Button control to False in Properties window.

UseSubmitBehavior="False"


it's work for me. My problem solved.

Tuesday, April 15, 2008

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Try to upload picture and hit below error.




A generic error occurred in GDI+.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 469: MemoryStream mem = new MemoryStream();
Line 470: resizedImage.Save(mem, jpegICI, encoderParams);
Line 471: resizedImage.Save(filePath + "\\" + fileName, ImageFormat.Jpeg);
Line 472:

Source File: c:\Inetpub\wwwroot\BlogA\Account.aspx.cs Line: 471

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
Account.WarpImageDimensions(String filePath, String fileName, Bitmap imageToSave) in c:\Inetpub\wwwroot\BlogarateNewLayout\Account.aspx.cs:471
Account.ImageButton1_Click(Object sender, ImageClickEventArgs e) in c:\Inetpub\wwwroot\BlogA\Account.aspx.cs:392
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

in my case:

It's caused by 2 thing:
1. Upload path - i put the wrong path
2. Folder permission - set the correct permission. In my case, i allow write permission for internet user (IUSR_xxxxx).

Problem solved.

Manage/Delete IIS log files using scheduler

Microsoft have provide a very good resource kits. Forfiles is one the them that we can use to manage our log files especially IIS log. My purpose for this article is to show how i use forfiles to help me to manage/delete my IIS log file more than 14 days (you can delete any time frame you want).

Steps:
1. download and install Windows Server 2003 Resource Kit Tools
2. write a bat script
3. create a scheduler


Let look at the details

1. download and install Windows Server 2003 Resource Kit Tools

In order to us it, you need to install it in your server first. Go to microsoft website "Windows Server 2003 Resource Kit Tools" and download it. After finish downloading, you can start to install it.
After finish installation, you can find Forfiles in C:\WINDOWS\system32\forfiles.exe


2. write a bat script

Syntax for forfiles

forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d[{+ -}] [{MM/DD/YYYY DD}]]

the details syntax you can get it from technet.

For me, i want to delete the log files date 14 days before. Below are some of the details
  1. log file location = C:\WINDOWS\system32\LogFiles\W3SVC1
  2. file type = *.log
  3. Date to delete = -d -14 (14 days before)

Below is the command that i'm able to come out and save it as .bat format. Say, "managelog.bat"

Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c "Cmd /C DEL @File"

copy forfiles.exe from C:\WINDOWS\system32\forfiles.exe and managelog.bat to the same location which you prefer.

3. create a scheduler

You need to create a scheduler to run the job automatically. For me, i run my job weekly at mid night 12:30AM.

To know how to create a window scheduler job, please find reference here.

Please test it before make it run automatically. I suggest that you use below command line to test. I change the DEL to ECHO so that i work safely.

Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c "Cmd /C ECHO @File"

Done. Good luck.

Sunday, April 13, 2008

Shrink Database MSSQL

Log file grow until very huge file? Check this step to shrink sql ldf file http://dotnetfish.blogspot.com/2007/12/shrinking-transaction-log.html

Thursday, April 10, 2008

Forbidden: Execute access is denied

The page cannot be displayed





You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.



Please try the following:



  • Contact the Web site administrator if you believe this directory should allow execute access.


HTTP Error 403.1 - Forbidden: Execute access is denied.


Internet Information Services (IIS)



During the application setting up, i miss out one step. That is Executive Permissions. To solve the problem, Select "Scripts Only" or "Scripts and Executables" under Executive Permissions option. Problem solved.


CS0101: The namespace '<global namespace>' already contains a definition for 'xxxxx'

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0101: The namespace '<global namespace>' already contains a definition for 'xxxx'




check whether you have a copy of the file with different name but using the same class (duplicate file). In My case, i have a backup copy for a aspx file. Delete the file or exclude from the project will solve the problem.

Thursday, April 3, 2008

Change Table and Stored Procedure Ownership From xxx to DBO

Need to change the ownership for table and stored procedure

Script for change table ownership

DECLARE @old sysname, @new sysname, @sql varchar(1000)

SET @old = 'oldOwner'
SET @new = 'dbo'
SET @sql = ' IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES
WHERE
QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?''
AND TABLE_SCHEMA = ''' + @old + ''' )
EXECUTE sp_changeobjectowner ''?'', ''' + @new + ''''

EXECUTE sp_MSforeachtable @sql


Credit should give to Scott Forsyth

change ownership for stored procedure

DECLARE
@OldOwner sysname,
@NewOwner sysname

SET @OldOwner = 'oldOwner'
SET @NewOwner = 'dbo'

DECLARE CURS CURSOR FOR
SELECT
name
FROM sysobjects
WHERE type = 'p'
AND
uid = (SELECT uid FROM sysusers WHERE name = @OldOwner)
AND
NOT name LIKE 'dt%' FOR READ ONLY

DECLARE @ProcName sysname
OPEN CURS
FETCH CURS INTO @ProcName
WHILE @@FETCH_STATUS = 0
BEGIN
IF @@VERSION >= 'Microsoft SQL Server 2005'
BEGIN
EXEC('alter schema ' + @NewOwner + ' transfer ' + @OldOwner + '.' + @ProcName)
exec('alter authorization on ' + @NewOwner + '.' + @ProcName + ' to schema owner')
END
ELSE
EXEC('sp_changeobjectowner ''' + @OldOwner + '.' + @ProcName + ''', ''' + @NewOwner + '''')

FETCH CURS INTO @ProcName
END

CLOSE CURS
DEALLOCATE CURS

Credit should give to Greg Duffield









Tuesday, April 1, 2008

Ping an IP through a specific port in cmd prompt or telnet

Well, sometimes we need to know whether the port in open or block, we need to do some checking or troubleshoot through ping/telnet. We cannot ping a IP with port but we can telnet certain IP together with Port no.

For example:
Go to open command prompt, if we want to check whether port 21 is working for IP 203.166.87.9 what we need to do is
> telnet 203.166.87.9 21

please tell me it's work. thanks

Sunday, March 16, 2008

Visual Studio .NET has detected that the specified Web Server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web applications o

I've received error message when try to open visual studio.net.
Visual Studio .NET has detected that the specified Web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web applications or services

I suspect some of my newly installed application cause the webserver port change from 80 to others. My case is easy to solve, i uninstall my newly install app called: "Raysource" and it's work and running.

For more information on this error, please check in

http://support.microsoft.com/kb/817267

http://www.dotnetspider.com/kb/Article2476.aspx





Sunday, March 9, 2008

Exclusive access could not be obtained because the database is in use.

I try to restore a new database in MSSQL 2005 and hit error
Restore Failed For Server 'xxxx' (Microsoft.SqlServer.Smo)
Additional information:
System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)


This is mostly caused by others user/session is using the database at the same time. To check whether got others user accessing the same database, execute SP_WHO will show who is using the database. Execute KILL to kill the process. In my case, i want to kill process with spid = 53

execute SP_WHO -- See which process in running

Execute KILL 53 -- 53 is the process id spid that i want to kill before restore.

In my case, i restore the database using script instead of using the SSMS.

Below is the script that i use to restore without any issue.


RESTORE DATABASE RateMyPosts
FROM DISK = 'C:\Documents and Settings\DEV1\Desktop\RatePosts.bak' WITH REPLACE,
MOVE 'RatePosts' TO
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\RatePosts.mdf',
MOVE 'RatePosts_Log' TO
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\RatePosts_log.ldf'

Saturday, March 1, 2008

VBScript: disabled and enabled button

<html>
<head>
<title>VBScript Example: disabled and enabled button</title>
<SCRIPT Language="VBScript">
sub enableButton()
if frm.chkbox_1.checked = true then
frm.btn_1.disabled = false
else
frm.btn_1.disabled = true
end if

end sub
</SCRIPT>
</head>
<body>
<form name=frm>

<input type="checkbox" name="chkbox_1" value="ON" onclick="enableButton()"></input>
<input type="submit" value="I Agree" name="btn_1" disabled></input>

</form>
</body>
</html>

Friday, February 29, 2008

ASP.NET ATOM Feed auto-discovery

Adding a RSS feed auto-discovery code to your site is essentially a usability feature. It allows browsers capable of RSS auto discovery such as IE7, Firefox and Safari to display a nice RSS icon RSS.

Safari:



IE7:



Firefox:



How to do that?

add below code to your rss feed after <?xml version="1.0" ?>

<link rel="alternate" type="application/rss+xml" title="Top new 20 posts rated" href="http://www.xxxx.com/rss" />

or
for ATOM feed

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xxxx="http://www.xxxx.com/">

where http://www.xxxx.com/rss is the feed url

Let me know if you need more info.

Thursday, February 28, 2008

Visual Studio 2005: publish website error - target folder empty

Do you have experience that after you have successfully published your application but the target folder is empty?

  1. Click "Publish Web Site", enter "Target Location", and click OK
  2. Site builds successfully
  3. files in destination directory are deleted
  4. IDE shows "publish succeeded"
  5. Go to check target directory, it's empty.

In my case, it caused by mispell an HTML tag. Fix the tag help to fix the published problems.

If this not work for you, try this alternative suggested by other developers.

Fix IIS mappings for ASP.NET, run the Aspnet_regiis.exe utility:

  1. Click Start, and then click Run.
  2. In the Open text box, type cmd, and then press ENTER.
  3. At the command prompt, type the following, and then press ENTER:
    "%windir%\Microsoft.NET\Framework\version\aspnet_regiis.exe" -i
    In this path, version represents the version number of the .NET Framework that installed on server. Must replace this placeholder with the actual version number when type the command.

Tuesday, February 26, 2008

UPDATE ... INNER JOIN

Example:

UPDATE sm
SET sm.SysConfId = sc.Id
FROM tblSKUMat sm
INNER JOIN tblSysConf sc
ON sm.Id = sc.Id

Monday, February 25, 2008

ASP.NET Cookies is domain dependent

Cookies is Domain dependent. Cookies created under subdomain beta.mydomain.com will not able to retrive when access to www.mydomain.com. To ensure that we can retrive the same cookies, we need to specify the domain
For example, we want to write the information to cookies under mydomain when we access to url beta.mydomain.com

HttpCookie cook = new HttpCookie("mydomain");
Response.Cookies.Clear();
Response.Cookies.Add(cook);
cook["UserId"] = userId;
cook["Name"] = username.Text;
cook.Expires = DateTime.MaxValue;
Response.Cookies.Add(cook);

To retrive the cookies information:

if (Request.Cookies["mydomain"] != null)
{
if (Request.Cookies["mydomain"]["UserId"] != null && Request.Cookies["mydomain"]["Name"] != null)
{
Session["UserId"] = Convert.ToInt32(Request.Cookies["mydomain"]["UserId"].ToString());
Session["UserName"] = Request.Cookies["mydomain"]["Name"].ToString();
}
}

Sunday, February 17, 2008

Get value from dynamic (number) radio button using vbscript

Here is my scenario, i have a ratio button but i'm not sure how many radio button will be populated. It can be one or it can be more than one (Array). I've tried many way to make it work but fail. Finally come out with below work around.

On Error Resume Next
radCount = document.all.RadDynamic.length
If err.number <> 0 then
If document.all.RadDynamic.checked Then
strLogoID = strLogoID & "," & document.all.RadDynamic.value
End If
Else
For i=0 To document.all.RadDynamic.length -1
If document.all.RadDynamic(i).checked Then
strLogoID = strLogoID & "," & document.all.RadDynamic(i).value
End if
Next
End If

Wednesday, February 6, 2008

Happy Chinese New Year


Happy Chinese New Year!
心想事成!

Friday, February 1, 2008

Firefox - Secure and Faster Web Browser



The award-winning Web browser is now faster, more secure, and fully customizable to your online life. With Firefox 2, added powerful new features that make online experience even better.


1. Enjoy a Better Web Experience
Firefox 2 delivers helpful new features to make online experience more productive.




2. Stay Secure on the Web
Firefox continues to lead the way in online security, and now includes active protection from online scams to keep safer.


3. Personalize Your Browser
Choose from over a thousand useful add-ons that enhance Firefox. It’s easy to personalize Firefox to make it your own.

Thursday, January 31, 2008

Compiler Error Message: CS0016: Could not write to output file 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\xxxxxx\xxxx

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0016: Could not write to output file 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wholesales\xxxxx\xxxxx\App_Code.xxxxxxx.dll' -- 'Access is denied. '




After some antivirus activities, my partner development machine face issue above.

This may due to some permission setting in Temp folder. To solve it,

1. Go to %Systemroot%, normally C:\WINDOWS or C:\WINNT
2. Right-click the Temporary folder (mine is C:\WINDOWS\Temp) and select Sharing and Security. Select the Security tab and take a look at the list of “Group or user names:”
3. NETWORK SERVICE should be in the list. If it is not, click Add and type Network Service in the text box:

4. Make sure NETWORK SERVICE have Full Control in the Permissions list.

5. Click OK.

6. Restart IIS (Run iisreset)

Test on the web, and it solved.





If you still have the same problem, please check whether you are using McAfee antivirus. If yes, it's probably cause by the access protected properties setting in mcAfee antivirus. Please make sure you unchecked "Prevent execution of scripts from the Temps folder" in "Access Protection Properties"
To do so, right click on McAfee icon in Taskbar and Click on "VirusScan Console..."


Double click on "Access Protection" and a new "Access Protection Properties" window will pop out. Make sure you unchecked "Prevent execution of scripts from the Temps folder" under Block column. Click OK to close all the window.


Problem should be solved.

Friday, January 25, 2008

VBScript New Line

I do have some projects that written in Classic ASP. I come accross the case that need to draw NewLine in Classic ASP.

Response.Write (vbCrLf) solve my problem

Thursday, January 24, 2008

Create failed for Login 'xxx'. (Microsoft.SqlServer.Express.Smo)

I was trying to create a user with weak Login Name and password. Error message below shown.

Create failed for Login 'xxx'. (Microsoft.SqlServer.Express.Smo)
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)

The MUST_CHANGE option is not supported by this version of Microsoft Windows. (Microsoft SQL Server, Error: 15195)





What i do is uncheck the "Enforce password policy" when create the new user. This way you will not get the error message, but this is not the recommended way for the production Login Name and Password.





Problem solved.