Login issue when trying to connect to database
-
9 มิถุนายน 2555 13:35
I use a custom made web application to connect to sql server database. It connects fine but every time it redirects back with the wrong password, username message. I know that all passwords and user names are correct, but sql server disconnects right away after it checks for a user password.
2012-06-09 09:25:05,181 [5] INFO Login attempt -> username = `admin
2012-06-09 09:25:05,185 [5] INFO Connecting to Xtrax DB
2012-06-09 09:25:06,232 [5] INFO Connection to Xtrax DB succesfully established
2012-06-09 09:25:06,239 [5] INFO Validating user `admin':`admin'
2012-06-09 09:25:06,334 [5] DEBUG Executing SQL query `SELECT u.user_id, u.username, u.islocked, r.role, r.role_id, c.*
FROM USERS u INNER JOIN ROLES r ON u.role_id=r.role_id
LEFT JOIN CUSTOMER c ON u.user_id=c.user_id
WHERE username=@username AND password=@password : admin : fIdUH9Pz71AW4S1BGQDIemBGqOg='
2012-06-09 09:25:06,435 [5] INFO Xtrax DB disconnected
ตอบทั้งหมด
-
9 มิถุนายน 2555 14:11ผู้ดูแล
Do you get results when your run the query from SQL Server Management Studio? Can you post the relevant code snippet? Perhaps the parameter values are not being passed as expected.
Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
-
9 มิถุนายน 2555 15:27
I am getting the error message:"Must declare the scalar variable "@username".",
I am a very new in database development. What is the code snippet, where can I look for it?
Svetlana Skelaney
-
9 มิถุนายน 2555 15:54ผู้ดูแล
I am getting the error message:"Must declare the scalar variable "@username".",
I am a very new in database development. What is the code snippet, where can I look for it?
A code snipped is just a portion of the application code.
This error may mean that the parameter was not added to the command as expected. Below is an example C# code snippet that shows one method to add parameters to the command:
var command = new SqlCommand( "SELECT u.user_id, u.username, u.islocked, r.role, r.role_id, c.*" + " FROM USERS u INNER JOIN ROLES r ON u.role_id=r.role_id" + " LEFT JOIN CUSTOMER c ON u.user_id=c.user_id" + " WHERE username=@username AND password=@password;", connection); command.Parameters.Add("@username", SqlDbType.VarChar); command.Parameters.Add("@password", SqlDbType.VarChar); command.Parameters["@username"].Value = username; command.Parameters["@password"].Value = password;Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
- เสนอเป็นคำตอบโดย amber zhangModerator 11 มิถุนายน 2555 2:32
- ทำเครื่องหมายเป็นคำตอบโดย amber zhangModerator 19 มิถุนายน 2555 2:29