css

Tuesday, May 25, 2010

Enable long text retrieval in coldfusion

If you are ever going to use long text fields in mysql or a SQL server you will get a strange result when outputting this data. By default ColdFusion retrieves the number of characters specified in the Long Text Buffer setting (under the advanced settings of a datasource). When coldfusion stores the information of the database into an structure or variable it limits the number of characters (if you are using utf-8 by default about 4.000 characters will be stored). To prevend this behavior and to be able to display the complete content of the database cell you need to check the Enable long text retrieval (CLOB) in the advance settings of a data source.


Tuesday, May 18, 2010

32 bit components on 64 bit coldfusion

If you try to initiate an 32 bit component on the 64 bit version of coldfusion (e.g. <cfobject action="Create" class="MSXML2.ServerXMLHTTP" name="objSrvHTTP">)
you will get the following error:

An exception occurred when instantiating a COM object.
The cause of this exception was that: java.lang.RuntimeException: Can not use native code: Initialisation failed.
Unfortunately there is no easy solution for this problem. The only way to solve this is to install a 32bit version of coldfusion on a different server or workstation (or run it parallel on the same server). I know of two possible solutions for this problem.

Option 1
Install a 32bit version of coldfusion on a different server or workstation (or run it parallel on the same server). You can run the component on a 32 bit server or workstation. In my case i created a web services that executed the 32bit component and returns the result to the caller.

<cfcomponent>
<cffunction name="example" access="remote" returntype="struct" output="no">
<cfset pass_url="http://www.adobe.com/"">
<cfobject action="Create" name="objSrvHTTP" class="MSXML2.ServerXMLHTTP">
<cfset temp = objSrvHTTP.open("GET","#pass_url#")>
<cfset temp = objSrvHTTP.send("")>
<cfset websitedata=structnew()>
<cfset websitedata.responseBody = #toString(objSrvHTTP.responseBody)#>
<cfset websitedata.status = #left(objSrvHTTP.Status,3)#>
<cfreturn websitedata>
</cffunction>
</cfcomponent>

Option 2
Call the component in asp and return the data in a webservice or as html. The following example executes the MSXML2.ServerXMLHTTP component in aspx and writes the response to the page. This pages can be called from a coldfusion cfhttp tag. Please note i know very little of asp so this example could probebly be improved.

<%@ Page Language="VB" Debug="false" %>
<%   

dim page_url 
dim page_status  
dim page_responseBody
dim page_responseText
dim xmlhttp
dim mycharset
page_url =  Request.QueryString("weburl")   
xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")   
xmlhttp.open ("GET", page_url, false) 
xmlhttp.setRequestHeader("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729)")
xmlhttp.send ("")

'  page_status =  Cint(xmlhttp.status)
page_responseBody =  xmlhttp.responseBody
page_responseText =  xmlhttp.responseText

mycharset = "" 
mycharset= xmlhttp.getResponseHeader("Content-Type") 
If(inStr(mycharset,"charset")=0) Then  
mycharset = "ISO-8859-1" 
Dim pattern As String = "(?i)>META(.*)charset=\s*([^\s|^""|^']*)"
If( Regex.IsMatch( page_responseText, pattern ))   Then
Response.CharSet = Regex.Match( page_responseText, pattern ).Groups(2).ToString() 
End If
End If  

Response.CharSet = mycharset 
response.StatusCode = page_status
Response.BinaryWrite(page_responseBody)
' Response.Write(page_responseText)


xmlhttp = nothing

%>

Monday, May 17, 2010

Compare big integers in Coldfusion

Encountered a strange result in coldfusion when i was comparing big integers in coldfusion. In short you should never use the EQ operator when checking if two big integers are the same. This is because coldfusion almost always sees integers as java.lang.Double. So when comparing something like

<cfdump var="#1111111111111111112 eq 1111111111111111113#">

The result will be YES, instead of No. The solution for this strange behavior is to use the Compare function:

<cfdump var="#compare(1111111111111111112,1111111111111111113)#">

If the two big integers are the same this function will return 0 if they are not the same the function will return -1 or 1. In this case it will return -1.

More info on this topic can be found at Beware ColdFusion Floating Point Integers a blog by Barney Boisvert.

Wednesday, May 5, 2010

cfimage and mod rewrite

If you are Encountering problems serving cfimage images and using some sort of url rewriting program you might be interested in the following article from the bennadel site:

URL Rewriting And ColdFusion's WriteToBrowser Image Functionality (CFFileServlet)

In short you need to prevent your url rewriting program from redirecting URLs with the CFFileServlet folder in it.

Lyla Captcha and coldfusion 9

If you need to have a compatible script for captcha (e.g. running the script on a coldfusion mx server and on a coldfusion 8 and above server). You might be interested in the following solution i have used. First of all Lyla captcha is not compatible with coldfusion version 9 (haven't tested it on coldfusion 8 but i think it isn't compatible). As of coldfusion version 8 there is a cfimage tag which isn't compatible with coldfusion mx. To get a captcha script to work on both coldfusion mx and coldfusion 9 you can try the following.


<cfif left(server.coldfusion.productversion,1) gte 8>
<cflocation url="captcha-cf8.cfm">
<cfelse>
#Your Lyla captcha code here
</cfif>

The captcha-cf8.cfm file:
<cfset captchaimagepath=" getdirectoryfrompath(getcurrenttemplatepath())">

<cfimage fonts="Arial black" difficulty="medium" 
destination="#captchaimagepath#" text="12345" height="60" 
width="192" action="captcha">

<cfcontent deletefile="yes" file="#captchaimagepath#" 
type="image/png" reset="yes">

Connect to a microsoft database on another server

Accesing a microsoft database on another server also has some pitfalls. You may get the following error message:

java.sql.SQLException: [Macromedia][SequeLink JDBC Driver][ODBC
Socket][Microsoft][ODBC Microsoft Access Driver] '(unknown)

Adobe offers the following solution:

This error occurs when permissions are not set properly and you try to use the
ODBC Socket or the drive letter of the mapped drive to the database. Follow the
steps below to avoid the issue:
1.Make sure the user who logged onto the machine
has administrator rights.
2.Set that user to be the logon account for the
ColdFusion MX ODBC Server and ColdFusion MX ODBC Agent services in the Windows
services control panel.
3.Map a drive to the remote database.
4.Create the data
source in the ColdFusion Administrator using the Microsoft Access option, not
ODBC Socket.
5.Set the path to the database using the UNC path, such as the
following example: file://machine_name/databases/test.mdb
If you are using a 64 bit version of coldfusion and you want to access a 32 bit microsoft access database you also need to do the following:

- Read http://coldfusion9.blogspot.com/2010/05/connect-to-local-microsoft-access-32.html
- open C:\Windows\System32\odbcad32.exe
- click file dns
- click add
- select microsoft access driver
- click finish
- click select
- in the database name field enter the full unc path (e.g. file://server/folder/database.mdb)
- click ok
- enter desired datasource name (same name as in the coldfusion administrator datasources)

Connect to a local Microsoft Access 32 bit database from coldfusion 9 64 bit.

Follow the instruction on the following link http://forums.adobe.com/message/2000549. In short copy the Windows\SysWOW64\odbcad32.exe to Windows\System32\odbcad32.exe. Make sure you have backup of both files. Enter the new Windows\System32\odbcad32.exe file. Add the dns. Then add the dns through the coldfusion administrator (for the System Database File use - C:\windows\system32\system.mdw) . It will give an error don't worry it will work ( at least for me).

Running coldfusion on IIS 7.5 on windows 7 enterprise will not run coldfusion files.

You can encounter problems if IIS is not installed properly. Dale Fraser has written an excellent solution for this: http://dale.fraser.id.au/2008/05/coldfusion-8-vista-sp1-solution.html. In short you need to add a couple of iis features installed. Go to the control panel --> Programs and features --> click 'windows features on or off'. Install the features in the image below.

Kick-off

Hi there,

Well i thought about writing a blog for some time now. Finally i found some time to set it up. This blog will be about coldfusion and javascript solutions and problems i encounter during my daily work.

Greetings Nebu