带存储过程的登录脚本异常求助: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_Utentestarts with a number (like "7"), MySQL will implicitly convert it to an integer, sov_countgets that number (hence your constant 7 value when testing). - If
ID_Utentewas 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 toadSmallInt, but your stored procedure definesv_countas anINT(4 bytes). You should useadInteger(value3) instead. - The fourth argument (
40) is the length—integers don't need a length specification. Set this to0or omit it (depending on your ADODB version,0is 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.Executein anOn Error Resume Nextblock and checkErr.Numberto catch hidden issues. - Verify that your
MM_cn_STRINGconnection 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_countreturns0, then test with valid ones to get1—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

