Tuesday, June 19, 2007

SQLAuthority.com News - Journey to SQL Authority Milestone of SQL Server

SQLAuthority.com News - Journey to SQL Authority Milestone of SQL Server


I am very glad to write this 200th post of this blog. I would like to express my gratitude to all of YOU - my readers for continuously reading this blog. I receive many comments and emails with feedback, questions and suggestion everyday. I enjoy meeting few of you during this journey as well. Please do send me feedback and your request to make this blog better. Following is milestone of Journey to SQL Authority.

SQL Server Interview Questions and Answers Complete List Download (PDF)


SQL Server Database Coding Standards and Guidelines Complete List Download (PDF)

Find SQL Server Job or Post SQL Server Job

Lighter Side of SQL - SQL Humor

Subscribe to SQLAuthority.com by Email for Regular Update

SQLAuthority Feed

New Personal Homepage of SQLAuthority Author Pinal Dave

Updated Resume of SQL Authority Author

List of All Articles of SQL Authority Blog for Easy Navigation

List of My Favorite SQL Articles on SQLAuthority

Search SQLAuthority.com for Quick Search of SQL Keywords

Support Child Rights and You

Thank you,

Pinal Dave (http://www.SQLAuthority.com)

Tuesday, June 12, 2007

Visit New Blog on SQL Server - SQLAuthority.com

Hello All,

Visit my new Blog about SQL Server. I post there regularly.

http://blog.sqlauthority.com

Thursday, October 20, 2005

Align ColdFusion MX 7 Flash Forms using CSS

Goal:
Align ColdFusion MX 7 Flash Forms using CSS. Table less layout.

Story:

Tables are only for tabular data display.
CSS is the best to web programming we all know that by now.

ColdFusion MX 7 has feature of Flash Forms. I have come across this question many times. Many developers have asked that how to use HTML element in the flash forms and how to align the input fields. The solution is “Do not use table or other html element. Use CSS”. It is not that difficult at all. I have created this simple example for that.

Result:
It is very simple. Flash forms are aligned beautifully with CSS, no use of Table element of HTML.

Code:
<style type="text/css">
<!--
body {
font-family : "Lucida Grande","Lucida Sans Unicode",Verdana,sans-serif;
font-size : 70%;
color : #333;
background : #fff;
padding : 0;
margin : 0;
text-align : center;
}

#container {
margin : 0 auto;
padding : 0;
width : 770px;
text-align : left;
}
-->
</style>
</head>

<body>

<div id="container">
<form id="example-form" method="post" action="">
<fieldset>
<legend>Personal information</legend>

<label for="fm-req_forename">First name</label>
<div><input type="text" name="fm-req_forename" id="fm-req_forename" /> <br /> </div>
<label for="fm-req_forename">Last Name</label>
<div><input type="text" name="fm-req_surname" id="fm-req_lastname" /> <br /> </div>
<label for="fm-eml_email">Email</label>
<div class="fm-required"><input type="text" name="fm-eml_email" id="fm-eml_email" value=" " /> </div>
</fieldset>

<div id="fm-submit"><input type="submit" name="Submit" value="Submit" /></div>
</form>

Friday, October 14, 2005

CFFORM validation does not work

Goal:
CFFORM validation does not work.

Story:
I have faced this issue quite a few times so far. There are many ColdFusion servers, in my company. We keep on upgrading hardware of servers very frequently. Every new installation of operating system requires the installation of ColdFusion.

Personally, I like to use the regular FORM over CFFORM and write my own JavaScript validation. Well, there is a lot of “ancient” code, which we are cleaning up as we go. After importing all the code, configuration and settings while try to use forms sometime CFFORM does not work. When I move the same code to different server to test code it works as expected and when we move it back it does not work. This was quite a surprising problem for a while. We have blamed browser, operating system, domain etc thing for this issue; none of them are correct.

Problem:
The error we faced was

Line:8 Error: Object Expected

None of the JavaScript Validation worked. Form did not preserve any of the data which was posted back.

Solution:
The solution of this problem is not code, rather a configuration and adjustment to the server. The journey to find the solution was very interesting. I removed the CFFORM validation and tried to use simple form. No Luck! I uploaded the same code to another server on different domain, it worked fine. I re-wrote the CFFORM to regular HTML FORM and JavaScript validation. It worked fine. Well, it determines that Code was perfect but the there is something about CFFORM is not working. Carefully, observing the code, which is generated using CFFORM, I see following line of code.

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/CFIDE/scripts/cfform.js"></SCRIPT>

I played with that and I realize that cfform.js was physically there but missing as relative path for server. I checked the ColdFusion Administrator it was missing the path there.

I) I went to IIS & then map my CFIDE folder under my Web Site giving the alias as CFIDE.

II) After that I created mapping to my CFIDE folder in ColdFusion Administrator

III) I added new path like

Logical Path:/CFIDE

Directory Path: Z:\Inetpub\wwwroot\CFIDE

IV) Restart the ColdFusion Server.

CFFORM validation worked!

Result:
The solution will work when there is a lot of code using CFFORM on the server and “Object Expected” error occurs. This solution will help to fix the problem right away.

I highly recommended writing the code which does not use CFFORM. Please write your own HTML form and JavaScript validation; which gives far great control on that form element.

Online Reference:
ColdFusion MX 6.1: Hot fix for cfform controls
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_18951

Thursday, October 13, 2005

Best Reference Book for ColdFusion MX

The frequent question, I come across is “Which is the best reference book for ColdFusion MX?” I own almost all the book available for ColdFusion in my personal library. If I have to select only one book, I would recommend Macromedia ColdFusion MX 7 Web Application Construction Kit by Ben Forta. Following is my review on Amazon.com for the same book.

Must have 'significantly enhanced' MX 7 book


ColdFusion MX 7 Web Application Construction Kit (Web Application Construction Kit) by Ben Forta Ben Forta, Raymond Camden, Leon Chalnick, Angela C. Buraglia. ISBN: 0321223675

I just finished reading ColdFusion MX 7 Web Application Construction Kit. This is another master piece from Ben Forta. This book is definitely "significantly enhanced" than the previous version.

Like previous version it includes all the basic concepts from installing the ColdFusion to Database concepts, from data-entry forms to new Flash integration features. It is great as a guide to planning and making decisions about development than as a comprehensive reference. I have to say it is great in the manner of which it is written, and is easily understandable. All time favorite explanations in the book like next-n paging, error handling, User Defined Functions (UDF) and ColdFusion Components (CFC) are explained in same lucid and easy to understand language with examples.

In this new addition, the Flash applications are described in details with examples. The new features of Graphing, Printing, and Reporting are covered in length. The tricks and tips of the MX 7 like recursive directory search using cffile, flash forms, flash paper, Dreamweaver MX 2004 extensions are explained very well by authors.

Do not forget to read the additional chapters from CD-ROM. The appendix of the book is almost same as previous version with few changes. I will say this book is essential for beginners and advance ColdFusion MX 7 developer.

Pinal Dave (Macromedia Certified Advanced ColdFusion MX Developer)

Saturday, October 08, 2005

ColdFusion function using RegEX (Regular Expression) to verify special characters in URL

Goal:
Create the ColdFusion function using RegEX (Regular Expression) which verify string (URL) do not use special characters.

Story:
I came across situation when we allowed our clients to enter the URL variables in our system. The specification for URLs (RFC 1738, Dec. '94) poses a problem, in that it limits the use of allowed characters in URLs to only a limited subset of the US-ASCII character set. We can not have special characters in the URL. There is simple and easy explanation of this issue is at following site by Brian Wilson (http://www.blooberry.com/indexdot/html/topics/urlencoding.htm)

The special characters are as follows:

  • Dollar ("$")
  • Ampersand ("&")
  • Plus ("+")
  • Comma (",")
  • Forward slash/Virgule ("/")
  • Colon (":")
  • Semi-colon (";")
  • Question mark ("?")
  • 'At' symbol ("@")
  • Single Quotation marks ("’")
  • Double Quotation marks ("”")
  • 'Less Than' symbol ("<")
  • 'Greater Than' symbol (">")
  • 'Pound' character ("#")
  • Percent character ("%")
  • Left Curly Brace ("{")
  • Right Curly Brace ("}")
  • Vertical Bar/Pipe ("|")
  • Backslash ("\")
  • Caret ("^")
  • Tilde ("~")
  • Left Square Bracket ("[")
  • Right Square Bracket ("]")
  • Grave Accent ("`")

Result:
I wrote the ColdFusion function using Regular Expression (RegEx) which performs following tasks.

  • Returns (Displays) the error if special character is used in the string.
  • Returns (Displays) the special character to easily identify.

Code:

<!--- Function Begin -->
<cffunction name="CheckSpecialChars" output="false" returntype="struct">
<cfargument name="PageName" type="string" required="yes">

<!--- Creating the return variables. -->
<cfset arguments.SpecialCharsError = 0>
<cfset arguments.SpecialChar = ''>

<!--- Regular Experssion -->
<cfset regex = '[$|&|+|,|/|:|;|=|?|@| |/"|/''|<|>|##|.|%|{|}|\||^|~|\]|\[|`]'>

<!--- Following is the logic to determine the error and special chars -->
<cfif refind(regex, arguments.PageName)>
<cfset arguments.SpecialCharsError = 1>
<cfset r = refind(regex,arguments.PageName)>
<cfif find(" ", mid(arguments.PageName, r, 1))>
<cfset arguments.SpecialChar = '[space]'>
<cfelse>
<cfset arguments.SpecialChar = mid(arguments.PageName, r, 1)>
</cfif>
</cfif>

<!--- Creating the return structure -->
<!--- Returns: 1) Special Char Error 2) Special Char -->
<cfset arguments.retSpecialCharsCheck = StructNew()>
<cfset arguments.retSpecialCharsCheck.SpecialCharsError = arguments.SpecialCharsError>
<cfset arguments.retSpecialCharsCheck.SpecialChar = arguments.SpecialChar>

<!--- Return the Result Variable Structure -->
<cfreturn arguments.retSpecialCharsCheck>
</cffunction>
<!--- Function End -->

Online Reference:
Good Reference of special URL Encoding

http://www.blooberry.com/indexdot/html/topics/urlencoding.htm


RFC URL Encoding
http://www.rfc-editor.org/rfc/rfc1738.txt

Sunday, October 02, 2005

Create an Excel Spreadsheet dynamically using ColdFusion

Goal:
Best way to create an Excel spreadsheet dynamically using ColdFusion.

Story:
There are many occasions when I have to prepare the Excel Reports from database. I have two options

  • I run SQL query in query analyzer and open the Excel and copy the results.

  • I copy the query in my ColdFusion code and create the Excel File dynamically.

The advantages of the second options are:

  • I save lots of time

  • I can save the code file for future use.

  • I do not have to open two different programs (MS SQL and MS Excel) to do one simple job. I am able to do it right away in my HTML Editor. I use Dream Weaver but one can use Notepad.

  • I can give the name of the Excel file on the file.

  • If the data is changed, complete process can be done automatically running the same code again.

  • If we use cfschedule to run the schedule task, we can create the dynamic Excel file with dynamic name everytime.

Result:
I can produce Excel file in ColdFusion using dynamic data and dynamic file name on the fly.

Code:

<cfquery datasource="MyDataSourceHere" name="qryAccessData">
SELECT Field1, Field2, FieldN
FROM AccessTable
</cfquery>

<!--- cfheader will create the xls file download on fly (run of code) --->
<cfheader name="content-disposition" value="inline;filename=AccessToExcelDump.xls"> <!--- Mime type which will create the content type of Excel --->
<cfcontent type="application/msexcel">
<table border="1">
<tr>
<th>Field1</th>
<th>Field2</th>
<th>FieldN</th>
</tr><cfoutput query="qryAccessData">
<tr>
<td>#qryAccessData.Field1#</td>
<td>#qryAccessData.Field2#</td>
<td>#qryAccessData.FieldN#</td>
</tr></cfoutput>
</table>

Online Reference:

cfcontent http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-a17.htm#wp2850760

cfheader http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p56.htm#wp1355655