473,725 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Would special character cause insertion problem?

Hi,

SQL env: sql server 2000
Target column of insertion: varchar(15)

Case, a var is made up of a character of the following characters
(random selection):
A,B,C,D,E,$,!,% ,^,F,G,H,I,J,K, L,M,N,O,P,Q,R,S ,T,U,V,W,X,Y,Z, &,*,(,)
and a few numbers (random selection), and then

var = ran1&ran2

I'm experiencing intermit sql error
Is it because I did not include the string with quotes like
var = "ran1 & ran2"

or the first random seletion may include special character and that
may cause insertion error randomly?

Probably the former is more likely. And I've added quotes for the
var (programming language shouldn't really matter, int type usually
without quotes while strings need quotes).

What's your thought?

Thanks.

Oct 12 '07 #1
7 3676
Could you post your stored procedure or code?
Are you able to get an output of the sql string that will be used, the one
that throws the error.

--

Jack Vamvas
_______________ _______________ _____
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL


<ta********@gma il.comwrote in message
news:11******** *************@v 29g2000prd.goog legroups.com...
Hi,

SQL env: sql server 2000
Target column of insertion: varchar(15)

Case, a var is made up of a character of the following characters
(random selection):
A,B,C,D,E,$,!,% ,^,F,G,H,I,J,K, L,M,N,O,P,Q,R,S ,T,U,V,W,X,Y,Z, &,*,(,)
and a few numbers (random selection), and then

var = ran1&ran2

I'm experiencing intermit sql error
Is it because I did not include the string with quotes like
var = "ran1 & ran2"

or the first random seletion may include special character and that
may cause insertion error randomly?

Probably the former is more likely. And I've added quotes for the
var (programming language shouldn't really matter, int type usually
without quotes while strings need quotes).

What's your thought?

Thanks.

Oct 12 '07 #2
Hi Jack,

Very simple sql dml code (all the columns are of varchar of various
length):
insert into myTBL (col1,col2,col3 )
values ('#ranVar#','#F ORM.element1#', '#FORM.element2 #')

The err msg is:
Violation of PRIMARY KEY constraint 'PK__myTBL__772 828B3EFCA'. Cannot
insert duplicate key in object 'myUsers'.<P><P SQL = "insert into
myTBL (col1,col2,col3 ) values
('342*783','s** ************@st udent.org','s') " "

Actually sql server has successfully captured one record. Don't know
why it tries to capture it again. It would be nice to have many
simultanous users to use/test it... If you don't mind, http://www.mytata.net/,

Many thanks.

Don

On Oct 12, 11:01 am, "Jack Vamvas" <DEL_TO_RE...@d el.comwrote:
Could you post your stored procedure or code?
Are you able to get an output of the sql string that will be used, the one
that throws the error.

--

Jack Vamvas
_______________ _______________ _____
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL

<tatata9...@gma il.comwrote in message

news:11******** *************@v 29g2000prd.goog legroups.com...
Hi,
SQL env: sql server 2000
Target column of insertion: varchar(15)
Case, a var is made up of a character of the following characters
(random selection):
A,B,C,D,E,$,!,% ,^,F,G,H,I,J,K, L,M,N,O,P,Q,R,S ,T,U,V,W,X,Y,Z, &,*,(,)
and a few numbers (random selection), and then
var = ran1&ran2
I'm experiencing intermit sql error
Is it because I did not include the string with quotes like
var = "ran1 & ran2"
or the first random seletion may include special character and that
may cause insertion error randomly?
Probably the former is more likely. And I've added quotes for the
var (programming language shouldn't really matter, int type usually
without quotes while strings need quotes).
What's your thought?
Thanks.- Hide quoted text -

- Show quoted text -
Oct 12 '07 #3
(ta********@gma il.com) writes:
Very simple sql dml code (all the columns are of varchar of various
length):
insert into myTBL (col1,col2,col3 )
values ('#ranVar#','#F ORM.element1#', '#FORM.element2 #')

The err msg is:
Violation of PRIMARY KEY constraint 'PK__myTBL__772 828B3EFCA'. Cannot
insert duplicate key in object 'myUsers'.<P><P SQL = "insert into
myTBL (col1,col2,col3 ) values
('342*783','s** ************@st udent.org','s') " "

Actually sql server has successfully captured one record. Don't know
why it tries to capture it again. It would be nice to have many
simultanous users to use/test it... If you don't mind,
http://www.mytata.net/,
If I understood your initial post correctly, you generated the value
by some random process. Isn't it as simple that you are generating the
same value twice?

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 12 '07 #4
On Oct 12, 4:16 pm, Erland Sommarskog <esq...@sommars kog.sewrote:
(tatata9...@gma il.com) writes:
Very simple sql dml code (all the columns are of varchar of various
length):
insert into myTBL (col1,col2,col3 )
values ('#ranVar#','#F ORM.element1#', '#FORM.element2 #')
The err msg is:
Violation of PRIMARY KEY constraint 'PK__myTBL__772 828B3EFCA'. Cannot
insert duplicate key in object 'myUsers'.<P><P SQL = "insert into
myTBL (col1,col2,col3 ) values
('342*783','sig nmeeup728...@st udent.org','s') " "
Actually sql server has successfully captured one record. Don't know
why it tries to capture it again. It would be nice to have many
simultanous users to use/test it... If you don't mind,
http://www.mytata.net/,

If I understood your initial post correctly, you generated the value
by some random process. Isn't it as simple that you are generating the
same value twice?

--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se

Books Online for SQL Server 2005 athttp://www.microsoft.c om/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.c om/sql/prodinfo/previousversion s/books.mspx- Hide quoted text -

- Show quoted text -
Erland,

I'm not sure I follow you this time. Here's some additional info.
the 'sudo' code is (why not spelt like this? :)
set alphp = "A,B,C,D,E, $,!,
%,^,F,G,H,I,J,K ,L,M,N,O,P,Q,R, S,T,U,V,W,X,Y,Z ,&,*,(,)"
set ran1 = Right(Rand(),3)
set ran2 = Right(Rand(),3)
set ran3 = ListGetAt(alphp ,Right(Rand(),1 ))

-- and initially the following line read
set ran = #ran1#&#ran3#&# ran2#

-- now the following line reads
set ran = "#ran1#&#ran3#& #ran2#"

I suspected that I forgot to "close"/quote the string var of ran. And
that caused the intermittant error.

And I always appreciate your help.

Don

Oct 12 '07 #5
Sorry for security reason, I have to remove the previous post and
repost it with revision.

The err msg is:
Violation of PRIMARY KEY constraint 'PK__myTBL__772 828B3EFCA'. Cannot
insert duplicate key in object 'myTBL'.<P><P>
SQL = "insert into myTBL (col1,col2,col3 ) values
('342*783','sig nmeeup728...@st udent.org','s') " "
Actually sql server has successfully captured one record. Don't know
why it tries to capture it again. It would be nice to have many
simultanous users to use/test it... If you don't mind, http://www.mytata.net/,
Many thanks.
Don
On Oct 12, 11:01 am, "Jack Vamvas" <DEL_TO_RE...@d el.comwrote:
Could you post your stored procedure or code?
Are you able to get an output of the sql string that will be used, the one
that throws the error.
--
Jack Vamvas
_______________ _______________ _____
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL
<tatata9...@gma il.comwrote in message
news:11******** *************@v 29g2000prd.goog legroups.com...
Hi,
SQL env: sql server 2000
Target column of insertion: varchar(15)
Case, a var is made up of a character of the following characters
(random selection):
A,B,C,D,E,$,!,% ,^,F,G,H,I,J,K, L,M,N,O,P,Q,R,S ,T,U,V,W,X,Y,Z, &,*,(,)
and a few numbers (random selection), and then
var = ran1&ran2
I'm experiencing intermit sql error
Is it because I did not include the string with quotes like
var = "ran1 & ran2"
or the first random seletion may include special character and that
may cause insertion error randomly?
Probably the former is more likely. And I've added quotes for the
var (programming language shouldn't really matter, int type usually
without quotes while strings need quotes).
What's your thought?
Thanks.- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Oct 12 '07 #6
(ta********@gma il.com) writes:
I'm not sure I follow you this time.
And I am not sure that I am following you. You post some loose bits of
code that I don't really know what language it is. In the middle of at
you get an SQL error:

Violation of PRIMARY KEY constraint 'PK__myTBL__772 828B3EFCA'. Cannot
insert duplicate key in object 'myUsers'

This error can have two reasons:

1) You insert multiple rows with INSERT SELECT and the SELECT produces
duplicate keys.
2) You attempt to insert a key value which is already there.

From what I make make out of your posts, you use INSERT VALUES to insert
a single row. This rules out the first possibility, and I conclude that
you attempt to insert a row with same key as an existing row. You say,
"Actually sql server has successfully captured one record. Don't know
why it tries to capture it again." But this is nonsense. SQL Server
does not go out in the wild to capture "capture rows", but sits there
waiting to be spoon-fed.
the 'sudo' code is (why not spelt like this? :)
set alphp = "A,B,C,D,E, $,!,
%,^,F,G,H,I,J,K ,L,M,N,O,P,Q,R, S,T,U,V,W,X,Y,Z ,&,*,(,)"
set ran1 = Right(Rand(),3)
set ran2 = Right(Rand(),3)
set ran3 = ListGetAt(alphp ,Right(Rand(),1 ))

-- and initially the following line read
set ran = #ran1#&#ran3#&# ran2#

-- now the following line reads
set ran = "#ran1#&#ran3#& #ran2#"

I suspected that I forgot to "close"/quote the string var of ran. And
that caused the intermittant error.
Why would the quotes have anything to do with a primary key violation?

If you go on generating random keys like this, you will sooner or later
generate a key that you have already generated. And if you don't have any
code to handle this, you will get a primary key violation when you try
to use the already existing key value.

Rather than using anything homegrown, why not use a GUID if you want a
random key? A GUID is a 128 bit-value and there function both in
Windows and SQL Server that generates GUIDs that are guaranteed to be
unique all over the planet. In SQL Server the data type for a GUID is
uniqueidentifie r and you use newid() to generate a value.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 13 '07 #7
On Oct 13, 11:56 am, Erland Sommarskog <esq...@sommars kog.sewrote:
(tatata9...@gma il.com) writes:
I'm not sure I follow you this time.

And I am not sure that I am following you. You post some loose bits of
code that I don't really know what language it is. In the middle of at
you get an SQL error:

Violation of PRIMARY KEY constraint 'PK__myTBL__772 828B3EFCA'. Cannot
insert duplicate key in object 'myUsers'

This error can have two reasons:

1) You insert multiple rows with INSERT SELECT and the SELECT produces
duplicate keys.
2) You attempt to insert a key value which is already there.

From what I make make out of your posts, you use INSERT VALUES to insert
a single row. This rules out the first possibility, and I conclude that
you attempt to insert a row with same key as an existing row. You say,
"Actually sql server has successfully captured one record. Don't know
why it tries to capture it again." But this is nonsense. SQL Server
does not go out in the wild to capture "capture rows", but sits there
waiting to be spoon-fed.
the 'sudo' code is (why not spelt like this? :)
set alphp = "A,B,C,D,E, $,!,
%,^,F,G,H,I,J,K ,L,M,N,O,P,Q,R, S,T,U,V,W,X,Y,Z ,&,*,(,)"
set ran1 = Right(Rand(),3)
set ran2 = Right(Rand(),3)
set ran3 = ListGetAt(alphp ,Right(Rand(),1 ))
-- and initially the following line read
set ran = #ran1#&#ran3#&# ran2#
-- now the following line reads
set ran = "#ran1#&#ran3#& #ran2#"
I suspected that I forgot to "close"/quote the string var of ran. And
that caused the intermittant error.

Why would the quotes have anything to do with a primary key violation?

If you go on generating random keys like this, you will sooner or later
generate a key that you have already generated. And if you don't have any
code to handle this, you will get a primary key violation when you try
to use the already existing key value.

Rather than using anything homegrown, why not use a GUID if you want a
random key? A GUID is a 128 bit-value and there function both in
Windows and SQL Server that generates GUIDs that are guaranteed to be
unique all over the planet. In SQL Server the data type for a GUID is
uniqueidentifie r and you use newid() to generate a value.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se

Books Online for SQL Server 2005 athttp://www.microsoft.c om/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.c om/sql/prodinfo/previousversion s/books.mspx
Excellent, Erland, thank you.

Oct 13 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4558
by: Bal | last post by:
Hi, I am trying to generate a pdf using a XML file and rendering the page through XSL Stylesheet to a PDF. But the page has some special characters, as its for a chequ website. My Code below is <--xsl:page--> <?xml version="1.0" encoding="UTF-8"?>
4
432
by: Norman Uhlenkott | last post by:
I would like to be able to put in special character inside an xml data string (#, <, >, &). when it trys to parses out the XML String it errors out strXML = "<?xml version='1.0'?>" & vbCRLF strXML = strXML + "<WO_Step>" & vbCRLF strXML = strXML + "<Test>Test Special Characters #, %, &, <, > </Test> strXML = strXML + "</WO_Step>"
50
4349
by: The Bicycling Guitarist | last post by:
A browser conforming to HTML 4.0 is required to recognize &#number; notations. If I use XHTML 1.0 and charset UTF-8 though, does &eacute; have as much support as é ? Sometimes when I run the TIDY utility on my code, it replaces my character notations with weird looking things I don't recognize. Also, when I converted to UTF-8 from ISO-8859-1, I discovered many special characters
2
2284
by: Ozer | last post by:
Hi friends, I wanna ask something. I use javascript menu on my user interface. And the js files contains special(turkish) character. I need to use codepage=1254 attribute in my @Page tag. If i don't use it. Javascript menu and functions fail. But if i add this atrribute, after i posted the form, all of the special(turkish) characters becomes deleted. Thanks for any help. Bye.
1
4568
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file, 2. Text checks for max. length of the field & whether the field is mandatory or optional Example:
3
14670
by: jeyabarani | last post by:
Hi guys, I want to check whether the user has entered any special characters in a text box. If the user enters, i want to display an alert message stating that he cant enter a special character (like Ç). I have written a code wherein i am specifying the list of characters that are not allowed. It would be better if i can give a list of characters that are allowed instead of list of characters that are not allowed. And check whether...
1
2429
kaleeswaran
by: kaleeswaran | last post by:
Hi! i am handling password generation module..... i need to force the user enter the special character in their password thing.so i need to handle the special character.so how do i check if the user enter the special character or not?... waiting for ur's response.... thank you, kaleeswaran
1
1528
by: Ragavendran | last post by:
Hi, I am using this method for search: Query =org.apache.lucene.queryParser.QueryParser.parse(String arg0) throws ParseException Hits = org.apache.lucene.search.Searcher.search(Query query, Sort sort) throws IOException Problem : I cant able to search the word. If the word contain special character like , %BF It just taken that special character a empty space and search the remaining character
6
10710
vekipeki
by: vekipeki | last post by:
I am having a problem with basic drawing of unicode characters in Windows 2000 and XP. I have written a simplest possible C# WinForms program to test it (just create a new Windows Forms C# application and add a Paint event handler): public partial class Form1 : Form { public Form1() { InitializeComponent();
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.