Thursday, September 16, 2010

Update Collation SQL Server

Still talking about implementing foreign characters to your application. in SQL Server database we know what so-called Collation. you need to set the collation of the database and the table’s column to collation type that support to keep the foreign characters into the table. what I’m going to show here, is a solution for a problem that you may have when you want to alter table collation in a situation where there’s numerous number of tables to alter. hope this below SQL script might help you

 declare   
@NewCollation varchar(255)
,@Stmt nvarchar(4000)
,@DBName sysname
set @NewCollation = 'Thai_CI_AS' -- change this to the collation that you want to use
set @DBName = DB_NAME()
declare
@CName varchar(255)
,@TName sysname
,@OName sysname
,@Sql varchar(8000)
,@Size int
,@Status tinyint
,@Colorder int
declare curcolumns cursor read_only forward_only local
for select
QUOTENAME(C.Name)
,T.Name
,QUOTENAME(U.Name) + '.' +QUOTENAME(O.Name)
,C.Prec
,C.isnullable
,C.colorder
from syscolumns C
inner join systypes T on C.xtype=T.xtype
inner join sysobjects O on C.ID=O.ID
inner join sysusers u on O.uid = u.uid
where T.Name in ('varchar', 'char', 'text', 'nchar', 'nvarchar', 'ntext')
and O.xtype in ('U')
and C.collation != @NewCollation
and objectProperty(O.ID, 'ismsshipped')=0
order by 3, 1
open curcolumns
SET XACT_ABORT ON
fetch curcolumns into @CName, @TName, @OName, @Size, @Status, @Colorder
while @@FETCH_STATUS =0
begin
set @Sql='ALTER TABLE '+@OName+' ALTER COLUMN '+@CName+' '+@TName+ isnull ('('
+convert(varchar,@Size)+')', '') +' COLLATE '+ @NewCollation
+' '+ case when @Status=1 then 'NULL' else 'NOT NULL' end
begin try
exec(@Sql)
end try
begin catch
--error catch
set
print error_message()
end catch
fetch curcolumns into @CName, @TName, @OName, @Size, @Status, @Colorder
end
close curcolumns
deallocate curcolumns


you can run the script in SQL server 2005 or above, well, that’s a little trick for me, hope can help.



Thanks to Kim that had helped me on this :)

Sunday, August 29, 2010

Today’s Tips – Use Thailand Character, Database Collation

Here I am again, with the problem : how to use non-Latin characters in your Application ?

at the Programming side, you need configure the ColdFusion so it can support the non-Latin characters, please see my previous post that explain how to do it, but now, we’ll go with the database.

I assume you usually creates an application in EN localization, that’s why, by default, all the setting will refer to EN. included your SQL database collation, which by default, it can not merely accept the Thailand’s characters since the Collation is Latin. the solution is : you need to update the Database and Table Column’s Collation.

Collation for EN localization default is SQL_Latin1_General_CP1_CI_AS (at least this default collation where my Computer Server is installed)

in Thai, you need to use THAI_CI_AS collation (at least this what I used by now, probably you can use THAI_CI or other THAI collation).

1. Update Database Collation. to Alter the database collation, you can go to SQL Management, under the Object Browser, find the database you want to alter. then right-click to edit the database properties. you will find Collation options in the pop up screen, then you need to select the THAI_CI_AS for the database collation.

please note that you can update the collation if Database is not being used, if it is, then you can Restart the SQL server and try again.

2. Update Table’s Column Collation. You can run this SQL script to alter the column’s collation. (just example, you can modify the table name and column name) :

 ALTER TABLE temployee ALTER COLUMN first_name varchar(50) COLLATE THAI_CI_AS  


Then now, after you update the database and table’s column collation, you Now should be able to put Thai character to the database. This solution can be implemented in Database which has only less number of tables, but how if you has hundreds of Tables ? please find the tips on my next Post :)



Until next time, keep cheer up !

Today’s Tips – Use Thailand Character in ColdFusion

images Have you guys ever involved in project where you need to use non-Latin character ? I did

I came across with problem to make my application to run the Thailand’s characters. if you usually develop the CF application in English localization, probably, you cannot merely apply the foreign characters. (you will find the characters in unknown format)

and how the simplest way to solve this ?

Update the ColdFusion encoding to UTF-8. you can do this by go to CFIDE administrator, under Java and JVM tabs, and in the JVM Parameters, add the additional Parameter : -encoding=UTF-8

and Restart your CF application server

Now you should be able to put the Thailand’s characters in your CF application. I never used any other characters except Latin and Thai, but I’m pretty sure it will be the same encoding if you want to use another characters such as Chinese, Russian, or maybe Arabian.

well, after this, you probably will find another problem, in regard to the database collation. I will give you some tips in my next post,

Hope can Help,

Stay tune and Cheer up your Monday !!

Friday, August 27, 2010

Hello ! ColdFusion

been so long time no write anything on this site, what can I say, I just want to say hello !

wonder how to write this in ColdFusion ? for you who never know ColdFusion before please use this line :

 <cfoutput>  
Hello
</cfoutput>


finally, welcome to Coldfusion readers !

Tuesday, July 29, 2008

Coldfusion Randomizing Password

I had a problem when I needed to distribute an user name and password to each user registered in my application that written in Coldfusion. For security purpose, I needed to those password randomized before I send it. so, I was googling and found the interesting one. here you go.

 <cfset strLowerCaseAlpha = "abcdefghijklmnopqrstuvwxyz" />  
<cfset strUpperCaseAlpha = UCase( strLowerCaseAlpha ) />
<cfset strNumbers = "0123456789" />
<cfset strOtherChars = "~!@##$%^&*" />
<cfset strAllValidChars = (strLowerCaseAlpha &strUpperCaseAlpha &strNumbers ) />
<cfset arrPassword = ArrayNew( 1 ) />
<cfset arrPassword[ 1 ] = Mid(strNumbers,RandRange( 1, Len( strNumbers ) ),1) />
<cfset arrPassword[ 2 ] = Mid(strLowerCaseAlpha,RandRange( 1, Len( strLowerCaseAlpha ) ),1) />
<cfset arrPassword[ 3 ] = Mid(strUpperCaseAlpha,RandRange( 1, Len( strUpperCaseAlpha ) ),1) />
<cfloop index="intChar" from="#(ArrayLen( arrPassword ) + 1)#" to="8" step="1">
<cfset arrPassword[ intChar ] = Mid(strAllValidChars,RandRange( 1, Len( strAllValidChars ) ),1) />
</cfloop>
<cfset CreateObject( "java", "java.util.Collections" ).Shuffle(arrPassword) />
<cfset strPassword = ArrayToList(arrPassword,"") />

Saturday, July 26, 2008

Greetings

Hi everyone,

I start to take off from something sounds : "Let Share". for the comment, I highly appreciate.