SQL服务器:语句已被终止

时间:2015-08-06 17:55:29

标签: sql sql-server asp-classic

我已经为这个错误工作了大约两个小时,我觉得我的查询没有错误,但我一直得到这个错误。最糟糕的是它没有提供有关导致错误的更多信息。我使用ASP经典和SQL服务器。你能帮帮我们吗?这是我的疑问:

    query = "INSERT INTO [127.0.0.1].[tv].[dbo].[BH_REG]([REG_ID],[NAME],[PHONE],[EMAIL],[INST_ADDRESS],[ZIPCODE],[BIRTH_PLACE],[BIRTH],[SEX],[CABLE_DISTANT],[SID],[BID],[STREET_NUMBER],[PID], [REG_DATE], [REG_STATUS], [ORDER_STATUS], [ID_TYPE], [ID_NUMBER], [PROMO_CODE], [VIRTUAL_NUMBER], [BCA_ID], [SALES_CODE], [MAIN_PACKAGE], [MOBILE_PHONE], [PAY_METHOD], [COORDINATE], [TAP_ID], [TAP_PORT_ID],[EXPECTED_SCHEDULE]) "

query = query & "VALUES('"& idxx &"','"& name &"','"& mobilephone &"','"& email &"','"& instaddress &"','"& zipcode &"','"& birthplace &"','"& birth &"','"& sex &"','"& jarakKabel &"','"& sid &"','"& bId &"','"& streetNumber &"','"& aId &"', NULL,'COVERED','REGISTERED','"& idtype &"','"& idnumber &"','"& promoidtext &"','" & virtualcode &"', NULL,'"& salescode &"','"& PackageGroup &"','"& mobilephone &"','"& paymethod &"', '"& installationCoordinate &"', NULL, NULL, '"& expected_schedule &"')"
            Conndev.execute(query)

错误:

  

Microsoft OLE DB Provider for ODBC Drivers错误' 80040e14'

     

[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]语句已终止

     

/registration/register.asp,第256行

当我尝试在[REG_DATE]字段中插入getdate()时,我也收到同样的错误

在得到你们的一些线索之后,我试图参数化我的查询。不幸的是发生了另一个错误:

ADODB.Command error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

这里有更新的代码:

            <!--#include virtual="ADOVBS.INC"-->

            Set conn = Server.CreateObject("ADODB.Connection")
            conn.Open 'my connection string goes here
            set cmd = server.createobject("ADODB.Command")

            query = "INSERT INTO BH_REG (REG_ID,NAME,PHONE,EMAIL,INST_ADDRESS,ZIPCODE,BIRTH_PLACE,BIRTH,SEX,CABLE_DISTANT,SID,BID,FLOOR,STREET_NUMBER,PID,REG_DATE,REG_STATUS, ORDER_STATUS,ID_TYPE, ID_NUMBER, PROMO_CODE, VIRTUAL_NUMBER, BCA_ID, SALES_CODE, MAIN_PACKAGE, MOBILE_PHONE, PAY_METHOD, COORDINATE, TAP_ID, TAP_PORT_ID,EXPECTED_SCHEDULE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"


            cmd.ActiveConnection = conn
            cmd.CommandText = qText
            cmd.CommandType = adCmdText
            cmd.CommandTimeout = 900
            cmd.Parameters.Append cmd.CreateParameter("@REG_ID", adVarChar, adParamInput, 20, idxx)
            cmd.Parameters.Append cmd.CreateParameter("@NAME", adVarChar, adParamInput, 100, name)
            cmd.Parameters.Append cmd.CreateParameter("@PHONE", adVarChar, adParamInput, 100, mobilephone)
            cmd.Parameters.Append cmd.CreateParameter("@EMAIL", adVarChar, adParamInput, 100, email)
            cmd.Parameters.Append cmd.CreateParameter("@INST_ADDRESS", adVarChar, adParamInput, 500, instaddress)
            cmd.Parameters.Append cmd.CreateParameter("@ZIPCODE", adVarChar, adParamInput, 5, zipcode)
            cmd.Parameters.Append cmd.CreateParameter("@BIRTH_PLACE", adVarChar, adParamInput, 100, birthplace)
            cmd.Parameters.Append cmd.CreateParameter("@BIRTH", adDate, adParamInput, , birth)
            cmd.Parameters.Append cmd.CreateParameter("@SEX", adVarChar, adParamInput, 6, sex)
            cmd.Parameters.Append cmd.CreateParameter("@CABLE_DISTANT", adVarChar, adParamInput, 15, jarakKabel)
            cmd.Parameters.Append cmd.CreateParameter("@SID", adVarChar, adParamInput, 50, sid)
            cmd.Parameters.Append cmd.CreateParameter("@BID", adVarChar, adParamInput, 50, bId)
            cmd.Parameters.Append cmd.CreateParameter("@FLOOR", adVarChar, adParamInput, 100, NULL)
            cmd.Parameters.Append cmd.CreateParameter("@STREET_NUMBER", adVarChar, adParamInput, 50, street_number)
            cmd.Parameters.Append cmd.CreateParameter("@PID", adVarChar, adParamInput, 50, aId)
            cmd.Parameters.Append cmd.CreateParameter("@REG_DATE", adDate, adParamInput, , getdate())
            cmd.Parameters.Append cmd.CreateParameter("@REG_STATUS", adVarChar, adParamInput, 50, "COVERED")
            cmd.Parameters.Append cmd.CreateParameter("@ORDER_STATUS", adVarChar, adParamInput, 50, "REGISTERED")
            cmd.Parameters.Append cmd.CreateParameter("@ID_TYPE", adVarChar, adParamInput, 20, idtype)
            cmd.Parameters.Append cmd.CreateParameter("@ID_NUMBER", adVarChar, adParamInput, 100, idnumber)
            cmd.Parameters.Append cmd.CreateParameter("@PROMO_CODE", adVarChar, adParamInput, 50, promoidtext)
            cmd.Parameters.Append cmd.CreateParameter("@VIRTUAL_NUMBER", adVarChar, adParamInput, 100, virtualcode)
            cmd.Parameters.Append cmd.CreateParameter("@BCA_ID", adVarChar, adParamInput, 50, NULL)
            cmd.Parameters.Append cmd.CreateParameter("@SALES_CODE", adVarChar, adParamInput, 75, salescode)
            cmd.Parameters.Append cmd.CreateParameter("@MAIN_PACKAGE", adVarChar, adParamInput, 50, PackageGroup)
            cmd.Parameters.Append cmd.CreateParameter("@MOBILE_PHONE", adVarChar, adParamInput, 35, mobilephone)
            cmd.Parameters.Append cmd.CreateParameter("@PAY_METHOD", adVarChar, adParamInput, 25, paymethod)
            cmd.Parameters.Append cmd.CreateParameter("@COORDINATE", adVarChar, adParamInput,, installationCoordinate)
            cmd.Parameters.Append cmd.CreateParameter("@TAP_ID", adVarChar, adParamInput, 50, NULL)
            cmd.Parameters.Append cmd.CreateParameter("@TAP_PORT_ID", adVarChar, adParamInput, 50, NULL)
            cmd.Parameters.Append cmd.CreateParameter("@EXPECTED_SCHEDULE", adDate, adParamInput, , expected_schedule)

            set rs = cmd.Execute
            set rs = Nothing
            set conn = Nothing

以下是我参数化之前打印出来的查询:

INSERT INTO [127.0.0.1].[tv].[dbo].[BH_REG](
 [REG_ID],[NAME],[PHONE],[EMAIL],[INST_ADDRESS]
,[ZIPCODE],[BIRTH_PLACE],[BIRTH],[SEX]
,[CABLE_DISTANT],[SID],[BID], [FLOOR]
, [STREET_NUMBER],[PID], [REG_DATE]
, [REG_STATUS], [ORDER_STATUS], [ID_TYPE]
, [ID_NUMBER], [PROMO_CODE], [VIRTUAL_NUMBER]
, [BCA_ID], [SALES_CODE], [MAIN_PACKAGE]
, [MOBILE_PHONE],[PAY_METHOD], [COORDINATE]
, [TAP_ID], [TAP_PORT_ID],[EXPECTED_SCHEDULE]
)VALUES(
'H-10210-00276','ALFIN TEST','0888899998888',
'me@gmail.com','BENDUNGAN HILIR 3 NO : 22'
,'10210','','07/15/1981','M','Less than 50'
,'22794','','22','',getdate(),'COVERED'
,'REGISTERED','KTP','123235243212',''
,'8993774013523344', NULL,'','packet 1'
,'0888899998888','Kartu Kredit'
, '-6.2100422217393625,106.81154161691666'
, NULL, NULL, '08/15/2015'
)

2 个答案:

答案 0 :(得分:2)

任何推荐参数化查询更容易进行调试的人都会抽烟。 :)

这可能是由于您的一个或多个值与相应字段的数据类型不匹配引起的,但是试图找出哪一个是长参数列表中的问题会让您失去光头。相反,打开一个记录集(零行),执行.Addnew,并在代码中逐个设置每个字段。

Set rs = Server.Createobject("ADODB.Recordset")
query = "SELECT TOP 0 * FROM BH_REG"
rs.Open query, conn, 1, 2
rs.AddNew
    rs("REG_ID") = idxx
    rs("NAME") = name
    '...
    rs("EXPECTED_SCHEDULE") = expected_schedule
rs.Update
rs.Close
Set rs = Nothing

这样,ASP会告诉你究竟是哪一行造成了麻烦,你可以弄清楚它为什么是错误的数据类型,修复它/阻止它,然后那么就可以转换这一切都是存储过程或其他任何内容。

答案 1 :(得分:1)

这是一个黑暗中的镜头。您使用了许多NULL参数。那些毫无意义,只会增加混乱。参数化硬编码值也没有意义,所以也要删除。这是您的查询应该是什么样的。

INSERT INTO BH_REG 
(
    REG_ID
    , NAME
    , PHONE
    , EMAIL
    , INST_ADDRESS
    , ZIPCODE
    , BIRTH_PLACE
    , BIRTH
    , SEX
    , CABLE_DISTANT
    , SID
    , BID
    , STREET_NUMBER
    , PID
    , REG_DATE

    , ID_TYPE
    , ID_NUMBER
    , PROMO_CODE
    , VIRTUAL_NUMBER
    , SALES_CODE
    , MAIN_PACKAGE
    , MOBILE_PHONE
    , PAY_METHOD
    , COORDINATE
    ,EXPECTED_SCHEDULE
) VALUES
(
    ? 'regid
    , ? 'name
    , ? 'phone
    , ? 'email
    , ? 'inst_address
    , ? 'zip
    , ? 'birthplace
    , ? 'birth
    , ? 'sex
    , ? 'cable_distant
    , ? 'sid
    , ? 'bid
    , ? 'street_number
    , ? 'pid
    , ? 'reg_date
    , "COVERED"
    , "REGISTERED"
    , ? 'id_type
    , ? 'id_number
    , ? 'promo_code
    , ? 'virtual_number
    , ? 'sales_code
    , ? 'main_package
    , ? 'mobile_phone
    , ? 'pay_method
    , ? 'coordinate
    , ? 'expected_schedule
)

如果类型错误或者您遇到冲突,那是因为您设置了这些参数。我无法帮助你,因为它会在变量中并将它们转换为正确的数据类型。