Rexiology::Work

Microsoft, Information Technologies...

Community

News

  • From Taiwan, living and working at Tokyo, Japan.




Recent Posts

Tags

Microsoft Sites

Other Sites

Blog pools

Bloggers

Archives

Site Info



Locations of visitors to this page




Logos & Chicklets


GeoURL


Rex's Certifications
Rex's Certifications


Creative Commons授權條款
本 著作 係採用
Creative Commons 授權條款



January 2006 - Posts

Microsoft Update 0x80072EFD error...

 

Got a problem while upgrading to Norton Internet Security 2006. not happened to every computer but did happen in one of my case.

After installed Norton Internet Security 2006, when doing a Microsoft Update (online) , there might be "0x80072EFD" error occured and not able to connect to the service.

A search to Google find this site that's helpful. basically this should be caused by that NIS 2006 defaultly blocked 443 port connection. (seems Microsoft Update used port 443 for communication). after permitting the port access, the problem was solved.

This is not happened everytime. but might happen if one switched the network configuration and NIS 2006 didn't notice to create a new location for it (eg. only change a gateway or something minor). but if this happened. the problem above is possiblely able to occur.

To check if this is the cause of reason not able to do a Microsoft Update, first turn off NIS 2006 firewall and see if this still happens. if it did happen after disabled firewall, then it might be the internet connection problems that cause this issue. If firewall is disabled and Microsoft Update site is back to normal, then it might be the cause described above.

Technorati Tags: microsoft , nortonfirewall

 

IE6SP2 Download File Dialog Freezes...

 

Cost me hours to find this! thanks to the person who posted to Channel9!

Just got Hitachi 7K100 (2.5" HDD, 100GB, 8MB buffer, 7200rpm) and was going to reinstall my host OS on my notebook those 2 days.

after installing XP SP2 and started to install applications and tools, happened after several installations, IE6 just started freezing when trying to download and save files from internet. the download dialog just freeze before pop-up the file-location dialog box for user to choose.

I was originally thinking that maybe some of the installed programs corrupted IE6, so just un-install programs step-by-step reversely to see if IE6 will go back to normal. after several un-installations, all in vain!

later found the post at Channel9 that specify the problem of the cause! really thanks!!!

[via Channel9 Wiki]

Download File Dialog freezes

When the last location you saved to was a network path (eg. \\fileserver\myhomedir) the Download File dialog freezes (IE6SP2). This can be fixed by changing HKCU\Software\Microsoft\Internet Explorer\Download Directory to a local path. This happens to me often after working over a VPN.

-----------

This is exactly what happened to me!! after I checked that registry, exactly a network sharing directory on the record. that explain the reason why the download dialog will freeze there, cause the application was trying to locate that sharing directory.

After change the registry entry to a local path, everything back to normal!!! So I have to re-install all the programs that's been un-installed couple hours ago... Orz...

Technorati Tags: microsoft , internet explorerbug

 

Escape single quotation mark in sql query...

 

just a reminder of forming a sql query.

for concating strings in different databases, refer to my post here.

for concatenation, MS SQL uses " + " operator , Oracle uses " || " operator (as well as MySql uses function CONCAT() ) . so if one is designing a Data Repository using Repository Pattern, one may need to process this in repository level, which like providing a function for other code to concate strings in forming a query.

fortunately, for escaping single quotation mark in a query , it's the same as in MsSql and Oracle , they both used 2 single quotation marks to escape single quotation mark in a single-quotation-mark quoted string. (eg: for a string like o'connell to put in a query, it's 'o''connell' , " ' ' " is escaped and represents " ' ").

by the way, as NHibernate is just transforming object propertires in to real database field names, those rules above also apply to HQL query. also true if one is using escape chars in a "like" search (eg: select .. from class1 cls where cls.prop1 like '%My\\_Name%' escape '\\' ), the translation to real sql query both for mssql and oracle is tested without problems. 

Technorati Tags: hibernate , nhibernate , orm , database , programming

 

quotation marks and javascript...

 

It's all about Javascript when dealing with AJAX components...

When one is writing client functions, and needs to attach to event handlers, like:

<input type="button" name="aName" id="aID" value="Press Me!" onclick=" func1(); ">

It's simple when just calling a function to do things. Alternatively, one can also write multiple statements inside the onclick string:

onclick=" var str1='a string'; alert(str1); "

What about if one is going to dynamically generate a control (via string) and put it in some other controls innerHTML, like this:

var strshowmsg = "Show me as a string";
var strtrouble = "Show me as a string with \" exist also got ' exist!!!";
var strcontrol1 = "<input type=\"button\" id=\"button1\" name=\"button1\" value=\"Press Me!\" onclick=\"var str1='" + strshowmsg + "'; alert(str1);\">";
document.getElementById(strASpanTagID).innerHTML = strcontrol1;

It should be ok if the first string is going to output, but it should got script error when trying to show the second string because quotation marks crash pairing of strings.

strtrouble string variable often happened when strings are coming from a database or some user input. one never know what will be coming in (except telling user that only single quotation marks are allowed or what). in order to allow anything to be able to put in this kind of application, there is one way to do it.

var strcontrol1 = "<input type=\"button\" id=\"button1\" name=\"button1\" value=\"Press Me!\" onclick=\"eval(unescape('" + escape("var str1=\"" + strshowmsg.replace("\"","\\\"") + "\"; alert(str1);") + "'));\">";

The idea is to use eval to wrap whole javascript in a string and using escape / unescape to url encode the whole string to prevent any special chars, finally, explicitly escape double quotation marks inside the string coming from a variable output (from database, or user input) to ensure the whole escaped javascript statements are in the right way to output (since here using double quotation marks to wrap strings...).

Technorati Tags: asp.net , programmingajaxjavascript

 

Posted: 2006/1/19 2:17 by rextangtw | with 2 comment(s)
Filed under: ,
MSN Messenger 7.5.0322

 

just got auto-update notice this morning that MSN Messenger had a minor patch to 7.5.0322 ,

also there is Mess.Be Patch for 7.5.0322 available to download.

People will need this Mess.Be Patch to remove the ad banner also enable multiple accounts login, also some other tweaks...

Technorati Tags: msn , messenger

 

Posted: 2006/1/19 2:14 by rextangtw | with no comments
Filed under: ,
My turn to have VS.NET 2003 tell me "failure occurred while attempting to start compilation" ...

 

Annoying...

busy on writing my code and get this "failure occurred while attempting to start compilation" from vs.net 2003 , happened without a reason.

a search to Google found the reason of the cause (likely) [I am not lonely... Orz]. Seems too many projects in one solution will cause this error (I got 17 projects in a solution currently). some one got 67 projects provided a fix to solve this (thanks to Jeffrey to point out the link), but didn't work out to my situation (close vs.net, delete all pdb file by using "del *.pdb /s", open vs.net and compile again) .

Finally I got my situation solved by:

  1. Minimize projects in a solution to 13 projects.
  2. Close VS.NET 2003
  3. Delete all .pdb files in bin dir.
  4. Delete all .dll files in bin dir.
  5. Open VS.NET 2003 and compile again.

I know! this will be my last project using VS.NET 2003, will switch to VS.NET 2005 in next project.

... Or I know!! I'll start learning using NAnt..

Technorati Tags: asp.net , programmingvisualstudio

 

Posted: 2006/1/17 16:53 by rextangtw | with no comments
Filed under: ,
Setting up TTL for DNS records...

 

The follow-up of my company's SORB database issue (here and here).

I've asked my ISP to manually extend our company's rDNS record TTL to 86400 and now it passed the test from SORBS database.

just did a test trying to excluding the IP from the database and still get rejected. reason:

Checking MX's for xxx.com...
Rejecting MX 10 [TTL 13135] mail.xxx.com. (TTL too short)

No acceptable MX records found for wislite.com.

SORBS really did seriously checking to a dynamic IP !!! Orz

How to manually set DNS records TTL? by refering articles here and here:

; MX record Format:
; name          ttl  class  rr  pref     name
example.com.          IN    MX   10   mail.example.com.

; A record Format:
; name  ttl  class  rr        ip
joe           IN     A   192.168.254.3

$TTL 2d ; zone default = 2 days or 172800 seconds

just set ttl time between name and class will do. or just set default TTL for the whole domain.

Technorati Tags: email , smtp , sorbs , rdns , hinet , reverse dns

 

asp.net - initial values validation while page load or post back...

 

It's mostly required to do the initial values validation while an application start, no matter it's a winform or webform, a page taking values from query string or a web control taking values from attributes.

Lessons learned while doing my project, while doing a web user control. if main page will do many initial operations against a child web user control. the child web user control better doing it's all variable initiation at Page_Init event instead of a Page_Load. remembered the sequence of page event occurrence: Page_Init -> Load ViewState -> Page Load -> PreRender -> Render -> Page_Unload , till here the server side operation completed and web server send the renderred page to the client, this is the start time client javascript code take place. For composited control tree, started from page, the event occurrence start from root (the page), then followed by leaf controls. thus if in page's page_load there are many function calls to child controls, it might not get ready for control's initial value prepared for the main page or its own functions. therefore it should be better to put initial value setting and validation during page_init event, instead of page_load event.

It's common for page to take parameters from query string during post backs, also normal for web user control to get parameters from attributes specified from page or other controls. It would be a good practice to always validate those values before start processing logics.

for parameters there will always some values (mostly string values) pre-defined for user to specify. normally some integers, or strings like "true" or "false" or others custimized. by doing a initial value validation while page_init make sure the control gor the correct value and reduce the error handling inside logics. normally the validation code would like the following:

if (strValue1 == null) strValue1 = ""; // be sure always check null.
if (strValue1.ToLower() != "true" && strValue1.ToLower() != "false") strValue1 = "false";
if (strLevel == null) strLevel = "";
if (strLevel.ToLower() != "low" && strLevel.ToLower() != "middle" && strLevel.ToLower() != "high") strLevel = "middle";

this will get little lousy if a parameter got too many options to set.

null is always the thing needs to be checked, since one may not able to know if certain variable was initialized or not. make sure at least the string is not null, then for those lousy if statement, just found a way to reduce it, by using string comparison:

if (strLevel == null) strLevel = ""; // make sure it's not null to prevent runtime error
if ("_low,middle,high".IndexOf(strLevel.ToLower()) < 1) strLevel = "middle";
if (strValue2 == null) strValue2 = "";
if ("_1_2_3_4_5_6_".IndexOf(strValue2) < 1) strValue2 = "1"; // check if the value is 1~6.

using IndexOf to check the occurence of preferred values, reduce the if (...) ...; code needed. some notices of this are:

  • strLevel can not be null or it will cause run-time error. so check the null first.
  • Astring.IndexOf("") always return 0, which make sense anyway. this will be the same index value of first char of the string to be compared. therefore do not put comparing string from first position. instead, putting them started from the second char by putting a space or anything in the first char. and do the compared value that's " < 1 " instead of " < 0" .
  • for the concern of matching the wrong value wanted, eg intened to matching "1" inside the string "_123456" , but a value "12" comes in, it will match ( index at 1 ) but still got the wrong value required. put seperators between matching values should solve this (eg "_1_2_3_4_5_6_").
  • RegularExpression class should be the right one to choose for this operation, but it still seems too lousy to me.

this should reduce some amount of coding, also easy to understand the intension. and page or control will got correct and required values while processing logics thus reduce validation code needed.

Technorati Tags: asp.net , programming

 

Posted: 2006/1/13 1:46 by rextangtw | with no comments
Filed under: ,
Javascript - Select / UnSelect All checkbox...

 

Often used tricks on HTML / Javascript design to provide a select all / unselect all checkbox somewhere to make user a better UI experience.

Google search got many result about this, since it's already old tricks that's often used in many websites. but sometimes it's easy to forget about how to quickly write one in hand, I found this example that's simple and quick to understand and pick up.

Technorati Tags: asp.net , programming , javascript 

 

Posted: 2006/1/12 16:09 by rextangtw | with 1 comment(s)
Filed under: ,
Sync your CVS source trees with WinMerge...

 

Since I am not in a Unix / Linux world (yet) , gotta find my own way and tools to deal with such problems, in a windows way.

Situation as follows:

I kept a source tree in my own development VM to keep source integrated and shared between my team members, in a local LAN, mostly at on-site environment that might block various internet access ports (SSH, port 22, etc). That means I am managing a CVS server in my development VM and team members just submit code they modified and also update code others submitted (make sure you are using secure protocols to send your source around network).

There is the main source CVS repository in my company office, in some situations the customer site may also got a source tree for vendors to submit into. so there will be problems syncing the local cvs source tree (in my VM) and external source tree (main office or customer site).

Since "CVS" folders should not be touched while sync (contain version information to compare with), and the destination (main office, etc) may contain files that already deleted that need to clear, there should be something that need to be careful in order to prevent massing up my updated source which might spend couple days developed.

A quick way to should be just using WinCVS to change the CVSRoot of  master local copy from local to the destination, then just do a update->add content->commit to update the destination. but I do think that is too risky cause a miss could mass up my local copy no matter it's the miss made by myself or by any CVS client.

So I am developing my own safer way. comparing files myself using tools. my solution as follows:

First create a temp directory, checking out local copies both from local cvs repository and the destination cvs one (either using WinCVS or TortoiseCVS, I found it easier using TortoiseCVS), so I got 2 directories with different CVS meta info (the CVS folders contains different info for 2 cvs resposotories). next, using a batch file xcopy with exclude options to xcopy all the things from checked-out-ed local copy to destination one, EXCLUDING all CVS folders. now I got identical files in both directories without affecting cvs meta data. the latest thing should be remove deleted files in destination. for this I used WinMerge to help me. WinMerge not only help A LOT on comparing conflict source files, but also capable to compare 2 directories with all the differences. check WinMerge website for usage and you'll know what I am talking about. it also integrated very well with TortoiseCVS. so I can use WinMerge to find those files that I was deleted in local but still left in the destination. then it's easy for destination local copy to just do a remove of those files, and finally, an add content -> update -> commit should check-in all the source to destination cvs repository that's identically the same as my local source tree, without affecting my real working source.

I shall try out using a SubVersion repository in my next project.

Technorati Tags: windows , cvs , cvsnt 

 

Posted: 2006/1/11 2:06 by rextangtw | with no comments
Javascript - Casting to integer on arithmetic division...

 

Been rushing on my working project and coding a lot Ajax using Ajax.net lately. Had a lot of  re-practice back to javascript. here is a quick pick of one of them.

As Javascript been a weak-typed language, sometimes it's not able to cast a variable from one type to another. as in arithmetic division, if one wants to output an integer instead of a double or else, here is a way learned from this article that's useful:

a = ( b / c ) | 0

by using a bitwise OR operation to cast a float / double back to an integer, to have a way casting some numeric values back to desired form.

also there is a nice Javascript language reference I dig a lot during this coding. thanks for the help!

Technorati Tags: asp.net , programming , javascript 

 

Posted: 2006/1/9 13:12 by rextangtw | with 7 comment(s)
Filed under: ,
CommunityServer 1.1 , admin add links script error...

 

It's a minor but annoying problem for CommunityServer 1.1 . solved couple weeks ago.

When adding links in administration page, there will always have client javascript error saying that it must have a ")" exist. the count of the same error had a pattern related to the link category added, means if there were 5 categories there, everytime entering the link admin page, there will be 5 script error poped up.

After a dig into the source code, found the problem is caused by resource file. when the link page is rendering , there will be a block of javascript using a resource file error message inside a string variable. this variable using " ' " to embrace the string and happened that the resource string also got " ' " inside it, thus caused that whole javascript statement incorrect and cause the error.

the recourse file used is English resource file, located in /communityserver-website/Languages/en-US/Resources.xml , there is a resource at line 2482 like this:

<resource name = "ManageLinks_ConfirmDeleteCategory">Are you sure you want to delete this category? All of it's child links will be deleted as well.</resource>

the code that cause error is at the category delete button onclick event. which is like this:

onclick="return confirm('Are you sure you want to delete this category? All of it's child links will be deleted as well.');"

as obviously, that is the "it's" inside the " ' " string that caused the error, which is the resource string above.

to solve this, just remove the " ' " of that "it's" to "its" or some other things that don't have a " ' " inside, then it's done, no source code modification is needed.

A better way to solve this should be modify the source code checking the output string to see if it conflict the string formation in javascript layout.

A mirror post to CommunityServer Forum about this issue is posted at http://communityserver.org/forums/508956/ShowThread.aspx#508956 . hope this helps...

Technorati Tags: communityserver , asp.net , programming

 

ASP.NET - maintain page scroll position on a postback...

 

It's always inspiring reading msdn blogs, be sure you got the rss feed of them!

[via Robert Burke]

How do you maintain page scroll position after a postback?

Say you've got some really long page, perhaps with some huge Control -- like, say, a huge, edit-enabled GridView.  Someone clicks a link halfway down that page (like, say, the "Edit" link on one of the later entries in that huge GridView).  It generates a postback, and the page get refreshed to its *top* instead of half-way down.

If you want, instead, to maintain the page scroll on a postback, just set the MaintainScrollPositionOnPostback property on the Page.  You can do this declaratively (in your aspx Page directive) like so:

<%@ Page MaintainScrollPositionOnPostback="true" ... %>

If that's too heavy-handed a solution (i.e. you don't want to maintain scroll position for all postbacks), you can use the solution found on this page.

 

Technorati Tags: asp.net , programming 

 

Posted: 2006/1/5 22:59 by rextangtw | with 1 comment(s)
Filed under: ,
Multiple same ajax-enabled-web-controls with single sharing client script set in one aspx page...

 

I was dealing a general purpose web user control (ascx) with Ajax functionalities and may be used many times in a single aspx page.

Server side controls would layout their own client side IDs without duplications in a single page (asp.net will prefixed each client id with the control name specified in main aspx page). When writing client side javascript to deal with ajax functionalities, it should be awared that when multiple same controls existed in the same aspx page, some problems may occur.

Something may have duplicated client IDs or Names:

  • pure HTML tags (self-written span tags, div tags, input tags, etc to hold data dynamically)
  • javascript global variables
  • javascript functions

When loading multiple same controls into a single page, if there were javascript function calls written inside the ascx file, there will be multiple layout of same javascript blocks with functions of the same name, which will cause duplicate function definitions. in the mean time, if there were global client javascript variables sharing between javascript functions, it will also cause duplicated variable definitions when multiple same controls are loaded in a single aspx page.

for duplicated html tags, it can be corrected by putting the ascx contrl name prefixed, just like what asp.net did for server side controls. by using a <%=this.ClientID%> prefixed in html tag id attribute, self-written html tags can then be distinguished in the same page if multiple same controls were loaded into.

for duplicated function names and multiple same functions loaded into client page layout that causes useless bandwidth usages, there are 2 ways to overcome this problem. one is just like what I've done with html tags, using this.ClientID prefix to distinguish function names to avoid duplication. this can avoid function name duplication syntax error but, when multiple same controls are loaded in single page, there will be multiple functions with different function names but same functionality inside the client ouput, which will also cause useless bandwidth usages. The other way is trying to put only one instance of function sets in a single page for multiple same controls to consume. for this I found Chris Maunder's article about doing an improved RegisterClientScriptBlock function to avoid duplication javascript blocks as well as to organize all the client scripts in the same place. nice stuff and just what I need! thanks Chris for the sharing.

Chris' code will override RegisterClientScriptBlock function provided by Page class to automatically put script tag (<script ...> ... </script>) for the scripts passing into the function. it's nice to avoid layout error if user forgot to put the script tag for scripts, but it will also cause errors if the scripts passing into already got script tags inside. as it's an overrided function for page class, other controls in this derived page that using RegisterClientScriptBlock function to register client scripts will also be affected and causes multiple script tag parse error. to avoid this, it's better to modify the overrided RegisterClientScriptBlock function provided by Chris to add a check to see if there was already script tag inside the passing script string. I did encounter this problem since in the control I used Ajax.Net objects and it automatically register its own client scripts using this approach.

for duplicated global sharing variables, there are still 2 ways to resolve this problem. one is just like what asp.net did for server controls, adding this.ClientID prefix at each variable name, and then for function calls passing each necessary global variables in for processing. this would not be a good way since first of all the client side variables will be full of server side tags just like in old asp time, and second if there were lots of global sharing variables to pass into functions it would be a lousy function signature and considered as a bad practice.

the other way to work around this is to wrap all the global variables into a single array or object. using array got its weakness that using index to get certain variable requires knowledge of array layout structure. using object with properties for global variables would be a better way to do since it can achieve sort of "strong type" style and variables can be retrived by exactly the same global variable name without prefixing with this.ClientID (the only variable need to use this.ClientID to distinguish between multiple same controls is this main object that hold those global variables as properties!), which is good for code reading and preventing indexing wrong stuffs while using array approach.

for consolidating all client side global variables in a ascx control, it's good to use JSON syntax to fast organize them into a single useful object to be passed around all shared functions. for JSON stuffs refer to Steve Maine's post about JSON to get a more detail understanding about this.

Conclusions until here:

  • using this.ClientID server tag to prefix self-written client html tags
  • rewritten sharing functions for each ascx control which will potentially be used multiple times in the same page.
  • using Chris Maunder's customized RegisterClientScriptBlock function to settle down client functions without duplication.
  • using JSON to organize sharing client global variables into a single parameter object for easy function paramater passing.

one more trick to mention, for those sharing client functions, it's good to put them all into a single .js file and using Chris's RegisterClientScriptFile method to form a script tag with src attribute indicating the location of the .js file for the including. furthermore, if it is necessary to "dynamically" load different client functions based on different ascx control usage (eg: one ascx generic control with parameter that specifying using different user input like a dropdownlist or checkbox or listbox or radio button to layout an ajax output variable set, it may require different sharing functions regarding dealing different user input type interaction!), it would be good to change .js file into a .aspx file and passing querystring parameters and then  using server side tags to do conditional selection of functions to output (still old asp tricks). this will make the final client page layout more neat and elegant...

[Updated 2006/01/05 19:44]

Cautions when using Chris' solution to put all the client scripts in the same location! I was just encounted an issue that may not fit into Chris' approach.

By using Chris' approach he was using derived page's OnPreRender() event trigger to output all the scripts registered using overrided RegisterClientScriptBlock function. this shall successfully capture all the client scripts registrations without problem. BUT! something may be missing!

for a page contained many controls inside it, if all the sub-controls (including custom ones) all register its client script before it's OnPreRender() event trigger, which should be like at Page_Load(), or Page_Init(), etc, then everything should work out just fine.

according to what was stated in msdn help about RegisterClientScriptBlock function, this function allowed users to call it from anywhere around the code-behind life cycle, therefore if some controls using this function after PreRender event during the dynamic layout rendering time, then Chris' function won't be able to layout those later-added client scripts, although my test showed that the overrided function did successfully captured those later client script blocks, but since it's already passed the PreRender event, there won't be other time to really render those latter happened scripts, thus finally results missing of client script blocks.

I am wondering how asp.net's own page class processing this function that can get regiester client scripts everywhere during the code-behind life cycle and in the latest just rendering all of then in the place that's right behind the form tag, amazing...

Technorati Tags: asp.net , programming , ajax , ajax.net , json 

 

More XML Serialization and utf-8 encoding links...

 

I got the xml serialization tips post before. today I just found that the serialization won't work again. later found that it's cause by the encoding. seems the output string is back to utf-16 encoding and XML DOM's LoadXml() function won't be able to parse it and just throw an exception saying that the syntax is wrong at the very first char, although the whole node structure were right.

couple articles found very useful after a search to Google:

  • Shawn Steele's post "Avoid treating binary data as a String" talking about it should be careful converting between byte[] and string. this might affect my working since I am dealing with Traditional Chinese encoding in unicode.
  • Roy Osherove's post had comments of code samples about how to let StringWriter class be able to specify Encoding (originally read only).
  • Finally, Robert McLaws's post with comment thread featured XmlWriter PM Joshua Allen's explanation of string encoding and XmlWriter behaviors, very nice an article to clarify many topics faced around encoding and xml serialization in .net framework.

I'll still use MemoryStream to store utf-8 encoding during serialization, but I'll use Joshua's code sample to output the string instead of using MemoryStream.ToArray() stated in links found in my xml serialization tips post.

My project code is back to work as it should be after the code modification, but I shall do more test about it to see if Traditional Chinese chars in serialized xml string will make XML DOM object not able to load again. will keep an eye on it while testing phase.

Technorati Tags: c# , dotnet , programming ,xml , serialization , unicode , encoding 

 

Posted: 2006/1/3 18:59 by rextangtw | with no comments
Filed under: ,
More Posts Next page »