Application uses a value of the wrong type for the current operation in classic asp

久未见 提交于 2019-12-19 07:09:10

问题


I am calling one stored procedure using the following code:

m_objCmd.CommandText = "StoredProc_Name"
m_objCmd.Parameters.Append m_objCmd.CreateParameter("@UserID", 3, 1, 0, UserID)
m_objCmd.Parameters.Append m_objCmd.CreateParameter("@UserTypeID", 3, 1, 0, UserTypeID)
m_objCmd.Parameters.Append m_objCmd.CreateParameter("@AccessToken", 202, 1, 100, AccessToken)
m_objCmd.Parameters.Append m_objCmd.CreateParameter("@TokenExpiration", 135, 1, 0, TokenExpiration)
m_objCmd.Parameters.Append m_objCmd.CreateParameter("@RefreshToken", 202, 1, 100, RefreshToken)

rsUserData.Open m_objCmd, , adOpenStatic, adLockReadOnly  

In above:

  • @UserID is a 'int' dataType
  • @UserTypeID is 'int'
  • @AccessToken is nVarchar(100)
  • @TokenExpiration is datatime(2)
  • @RefreshToken is nVarchar(100)

But here I am getting the error:

Application uses a value of the wrong type for the current operation.

Can any one help me please.


回答1:


I had this same problem just a few days ago. My problem was overflow as Kul-Tigin suggests below.

I was trying to insert a huge string 17,000+ characters in length and I received exactly the same error as you. I then opted to save the string in a text file and I used the table as a file locator so-to-speak.

Check the length of the values in the following:

  • @UserID is a 'int' dataType
  • @UserTypeID is 'int'
  • @AccessToken is nVarchar(100)
  • @TokenExpiration is datatime(2)
  • @RefreshToken is nVarchar(100)



回答2:


Seems there is overflow or wrong type. For instance, length of AccessToken could bigger than 100. Check all of them. And if neccesary, convert variables to theirs subtypes (especially strings). Some third party components could returns variants, and cause this. i.e.

... ("@AccessToken", 202, 1, 100, CStr(AccessToken))
... ("@UserID", 3, 1, 0, CLng(UserID))
..



回答3:


Today i solved similar issue by limiting the value of variable to the datasize of a column.

e.g. if one of the column size is Varchar(500) and mapping value contains more than 500 characters. it will throw this exception in ADODB (VB6.0)

you can solve this by increasing the column data size or limiting the value to 500 chars, in vb6.0 u can use Left([variable_name],500)




回答4:


It may be that your code snippet in your question is just incomplete but I would expect to see this line present also for your intend usage:-

 m_objCmd.CommandType = adCmdStoredProc


来源:https://stackoverflow.com/questions/8354859/application-uses-a-value-of-the-wrong-type-for-the-current-operation-in-classic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!