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!
> 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 ...?
"John Smith" <bobwpg8...@sneakemail.com> wrote in message
news:7542a9b0.02022...@posting.google.com...
<%
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.
"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
> :
>
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>...
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...
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