简体   繁体   中英

How do I send unicode data to nvarchar field in stored proc with ado/vbscript?

I've been banging my head against the wall with this problem for the better part of two days, and my vbscript/ado is super rusty.

I inherited a legacy product. It contains a method that performs rudimentary encryption on some data before storing it and contains a decrypt method when the data is read from the database.

I can dump the encrypted value to the screen, then decrypt the encrypted value to the original just fine.

The problem is the database.

When I attempt to send this data to a stored proc, some of the characters are replaced with character # 65533 (diamond with a question mark). When the decrypt method gets a hold of this data, it doesn't know what to do with those odd characters.

I'm denoting that it's an nvarchar field with adVarWChar

Set cmd = Server.CreateObject("ADODB.Command")

cmd.CommandType = adCmdStoredProc
cmd.CommandText = "_sp_InsertData"
cmd.ActiveConnection = DefaultConnectionString

cmd.Parameters.Append cmd.CreateParameter("@somevariable", _
adVarWChar, _
adParamInput, _
255, _
MethodThatReturnsUnicodeDataThatDumpsToTheScreenJustFine())

cmd.Execute

Also: I can execute the stored proc via Sql Server Management Studio by pasting the encrypted data into the field and it works just fine. The decrypt method knows exactly what to do.

Make sure your ASP script (in notepad or whatever) is saved as UTF-8 format.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.ContentType = "text/html"
Response.CodePage = 65001
Response.CharSet = "UTF-8"
%>

This is the first include on all my ASP, since IIS7 you MUST put this for UTF-8 pages to display or save, it used to be optional in IIS6 (at least in Japanese versions of IIS I used)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM