You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

带存储过程的登录脚本异常求助:v_count值始终固定

Hey there, let's dig into your problem step by step. I spot a couple of critical issues that are causing your login script to fail, even though the proc works in Workbench.

1. 存储过程里的核心逻辑错误(最关键)

Look at the first line in your stored procedure:

select t_utenti.ID_Utente into v_count from t_utenti where t_utenti.login=v_login and t_utenti.pwd =v_pass;

You're assigning ID_Utente (a VARCHAR(45)) to v_count (an INT). That's a huge problem!

  • If ID_Utente starts with a number (like "7"), MySQL will implicitly convert it to an integer, so v_count gets that number (hence your constant 7 value when testing).
  • If ID_Utente was a non-numeric string, this would throw an error—but since it's returning a non-zero value every time, your ASP code thinks the login is valid regardless of credentials.

Fix this immediately: Change that line to count matching rows instead of selecting the ID:

SELECT COUNT(*) INTO v_count FROM t_utenti WHERE t_utenti.login = v_login AND t_utenti.pwd = v_pass;

This way, v_count will be 1 if the credentials are valid, 0 if not—exactly what you need for your login check.

2. ASP参数类型与长度不匹配

Your line for the @v_count parameter has mismatched settings for an integer output:

set objParameter = command.CreateParameter ("@v_count", 2, 2, 40)

Let's break this down:

  • The second argument (2) corresponds to adSmallInt, but your stored procedure defines v_count as an INT (4 bytes). You should use adInteger (value 3) instead.
  • The fourth argument (40) is the length—integers don't need a length specification. Set this to 0 or omit it (depending on your ADODB version, 0 is safer to avoid unexpected behavior).

Corrected line:

set objParameter = command.CreateParameter ("@v_count", 3, 2, 0)

Also, double-check your other output parameters: for example, @v_ID_Utente is a VARCHAR(45) in the proc, but you set length to 40 in ASP—match the length exactly to avoid truncation or odd behavior.

3. 额外的小建议

  • Add error handling in your ASP code! Right now, if the stored procedure throws an error (like the implicit conversion issue), you won't see it. Wrap your command.Execute in an On Error Resume Next block and check Err.Number to catch hidden issues.
  • Verify that your MM_cn_STRING connection string uses a MySQL ODBC/OLE DB driver that properly supports stored procedure output parameters (older drivers might have quirks with parameter handling).
  • After fixing the proc, test it again in Workbench with invalid credentials to confirm v_count returns 0, then test with valid ones to get 1—this ensures the proc itself works as expected before testing the ASP code.

Once you fix these issues, your v_count should correctly reflect whether the credentials are valid, and your login logic will work as intended.

内容的提问来源于stack exchange,提问作者Domenico Schitti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:06:55