Solved

Some chars are not accepted by SQL

Posted on 2001-06-28
5
236 Views
Last Modified: 2010-08-05
In my web project I have a large note field that should accept comments by the user. But I have found that some characters will not be accepted by SQL - one of those is the appostrophe "'". I also use a simple encryption routine that produces a lot of non-printable characters as the output and they too are sometimes rejected by SQL. I would think a text field should accept anything, but not true. My note field is very important and I cant limit what the user types in. How do a get around this problem?
0
Comment
Question by:rblackwell
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6234897
It will accept ' but in the query you have to send '' instead.

text field only accepts ascii characters - if you want it to accept characters that are not within that codeset you need to store as unicode and define the field as ntext.
You also need to deal with unicode values in this feld whenever it is accesed or the data transferred.
0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6234919
e.g.

insert tbl select 'gfhkf'gfhkg'

will fail

insert tbl select 'gfhkf''gfhkg'
will work.

For unicode try

select 'n'
and select N'n'
where n is the char in question. If it is a character set problem then the first one will translate the char.

0
 

Author Comment

by:rblackwell
ID: 6235006
Ok, this seems to make sense. Currently my PW field is set to nvarchar and it only accepts certain charaters. I changed it to ntext and my code would not authenticate anyone with any name, but as soon as I changed the field from ntext back to nvarchar the PW work (but still had the limitation). ??? Should I do something different in my code if the field is ntext? Sorry but i'm just a little confused by your second paragraph.
thanks
0
 
LVL 18

Accepted Solution

by:
nigelrivett earned 100 total points
ID: 6235109
What is the field supposed to hold - you only need ntext if the field needs to be more than 4000 chars.
text fields are a lot more difficult to manipulate than chars so should only be used if necessary.

The nvarchar field will accept any unicode character - if it is not then there is probably a problem with your interface. The field needs to be handled as unicode everywhere.

My last paragraph was pointing out that

insert nvarcharfield select 'ghjk'
will translate any non ascii characters whereas
insert nvarcharfield select N'ghjk'
will retain them
0
 

Author Comment

by:rblackwell
ID: 6239527
You pointed my in the correct direction. I found my com object was casting the incoming variables as Strings which of course do not hold Unicode inforation. Thanks for the lead.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question