Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inserting GUID to SQL

1 view
Skip to first unread message

John Smith

unread,
Feb 27, 2002, 5:31:14 PM2/27/02
to
Hello,

I have a template which generates a GUID then attempts to insert the
GUID into a SQL table. However, I keep running into the error
"Unclosed quotation mark before the character string '" during the
insert. I've included the offending code below:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open <connectionstring>
key = GetGuid()
strSQL = "INSERT INTO <tbl> (Key,email) VALUES ('" & key & "','" &
mail & "')"
objConn.Execute(strSQL)
objConn.Close
Set objConn = nothing

' taken from ASPFAQ.com
Function GetGuid()
Dim TypeLib
Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
GetGuid = TypeLib.Guid
Set TypeLib = Nothing
End Function

After much confusion, I realized that the ampersand after the key
variable is being ignored. Does anyone know why this might be
happening? Any help would be greatly appreciated.

Thank you!

Aaron Bertrand [MVP]

unread,
Feb 27, 2002, 5:46:23 PM2/27/02
to
What happens when you replace

> objConn.Execute(strSQL)

With

response.write strSQL
response.end

? Also how did you realize that the ampersand is being ignored? What's the
symptom, an error message, incorrect data, something else ...?

www.aspfaq.com

"John Smith" <bobwpg8...@sneakemail.com> wrote in message
news:7542a9b0.02022...@posting.google.com...

MVP - Aaron Bertrand

unread,
Feb 28, 2002, 12:28:51 AM2/28/02
to
Ah, I see the problem. There are two bogus characters at the end of the
GUID which are added when it comes out of the function. Experiment with the
following script:

<%
key = GetGuid()
newkey = left(key,len(key)-2)

response.write key
response.write "<p>"
response.write newkey
strSQL = "INSERT INTO <tbl> (Key,email) VALUES ('" & key & "','foo')"
response.write "<p><br>" & strSQL
strSQL = "INSERT INTO <tbl> (Key,email) VALUES ('" & newkey & "','foo')"
response.write "<p><br>" & strSQL

Function GetGuid()


Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
GetGuid = TypeLib.Guid
Set TypeLib = Nothing
End Function

%>

That's all the explanation I have for now, and it should solve your
short-term problem. As for the why, I'll look into it later (once I have
some more sleep under my belt). If anyone has any input as to why this
happens, please let us know.

www.aspfaq.com

"John Smith" <pch2dwz4...@sneakemail.com> wrote in message
news:1itq7ukhriuo4bcag...@nsa.gov...
> When I do a Response.Write strSQL, I get
>
> INSERT INTO <tbl> (key, email) VALUES ('{<GUID String >}
>
> I know that the ampersand is being ignored because if I do a
> Response.Write key & "hello!"
>
> the browser displays <GUID String> and not "hello1" (or any other
> ASCII characters). So I assumed that the ampersand is being ignored.
>
> I hope you know that I am not blaming the script I copied from your
> website, Aaron. ;)
>
>
> "Aaron Bertrand [MVP]" <aaronATaspfaq.com> wrote:
>
> :What happens when you replace

> :
>


John Smith

unread,
Feb 28, 2002, 11:10:51 AM2/28/02
to
Thank you so much! That worked beautifully.

How in the world did you figure that out, Aaron? I suspected bogus
characters, but I couldn't find any.

"MVP - Aaron Bertrand" <aaronATaspfaq.com> wrote in message news:<uuVj3iBwBHA.1572@tkmsftngp07>...

Aaron Bertrand [MVP]

unread,
Feb 28, 2002, 11:46:13 AM2/28/02
to
> How in the world did you figure that out, Aaron?

Luck, for the most part. I knew something was swallowing up characters
following the string, so I did this:

response.write(right(key,10))

Lo and behold, it printed 8 characters every time...

www.aspfaq.com


Douglas Webb (CompCon Tech)

unread,
Feb 28, 2002, 6:03:17 PM2/28/02
to
Hello Aaron and John!

My 2c on the origin of the bogus characters: I suspect that the GUID is
being generated by a Win32 API call, and that the NULL terminator is not
being cut off of the end of the BSTR result before it is being cast as a VB
string data type. I have run into similar problems concatenating strings
with string values being returned from API functions in VB.

Hope this helps.


--
Douglas Webb, MCP
Microsoft Developer Support, ASP.NET team

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
> From: "Aaron Bertrand [MVP]" <aaronATaspfaq.com>
> Subject: Re: Inserting GUID to SQL
> Date: Thu, 28 Feb 2002 11:46:13 -0500
> Newsgroups: microsoft.public.inetserver.asp.general

0 new messages