|
Hello guys,
I have created a web application, where i provide to users to login and log out, register, etc.
I have two databases (i only will use one of them at the end, but now i use them both just to test my application. I use One each time i run the app). I am using the Membership provider on both of those databases. I the Web.config file i point the app to use one of the two databases, by using this connection string:
<connectionStrings>
<clear/>
<add name="MyLocalSqlServer" connectionString="Data Source=THESAINT\SQLEXPRESS;Initial Catalog=UserAuthentication;Integrated Security=SSPI;"/>
</connectionStrings>
I have two problems i can't seem to figure out what is going on and why they happen. I have searched a lot , but didn't any post with similar problem.
I can successfully register and after login the registered user. The problem appears in this two scenarios:
1st. When i change the database name in the connection string, put the second database, run the application, and after put again the first database in the connection string and run again the application.
2nd. When i close the SQL Server Express 2008 R2 and then start it again.
Having done those scenarios above, if i try after to login with a user that is registered in any of the two databases, i keep getting message that the password or username is not correct(that is, the error message of the ASP.NET Login control).
But if i want to register a new user, i still can. I only cannot log in .
It seems like the application doesn validate the credentials when logging in.
Anyone had a similar problem or has an idea of what might be going here ??
I am really frustrated at this point ! I've searched a lot but nothing !
Thank you guys !
|
|
|
|
|
Your question is vague,
Maybe you have a space in the data you wrote in the database
like "john doe "
So when you query the value it doesn't match.
You have to use the trim()
|
|
|
|
|
What you didn't understand mate ? I tried to explain as simple as i could, but let me try to explain it again.
As i told you i have this application. The user can register, login, log out, change password, etc.
I am able to register new users from the registration form(ASP.NET CreateUserWizard). After having registered them, i can also log in successfully if i give the credentials of any of those users i registered.
But If i do one of the two steps below the error appears.
1. If i close the project and the database server(SQL Server Express 2008 R2)and after open it again, i cannot log in anymore with some of the registered users, as i could before closing the project.
2. If i try to:
i)change database(i have two DB, with different names but exactly the same
tables and columns inside)
ii)point my application in the connection string to the second database.
iii)run the application
iv) after put back the first database in the connection string
v) run the application
vi) try to log in with some user that is already registered
vii) Baam !! The user doesn't get authenticated. I get message that the password
and username are not correct, when before changing the database name,i could log in without
any problem.
And here is the strange thing that makes me crazy. After having done one of the two steps above, i still am able to register new users. The only thing i cannot do anymore, is log in with some user that already exists in the database.
I do not thing that it has to do anything with the Trim, because when i registered the users, i used very simple usernames and passwords without any white spaces, just for testing purposes.
I hope i made it more clear here now.
Thank you very much for taking the time to see this !
Regards,
Pier
|
|
|
|
|
That's much clearer than the previous explanation. I understood the first explanation, just sounded to me like the data input was malformed, so there was no match.
Well overall, connecting to a database is pretty straight forward, but does require a series of steps to make sure it works correctly, before writing 10K lines of code.
I just learned how to use Oracle 11.g, and it took me 3 days to figure the whole thing out from start to finish.
I can probably narrow down your problem, and can only condense it into a smaller format. The actual problem can be within a much larger scope of issues, ranging from connecting to actual table permissions.
Now you may think my post here is condescending, but it's designed to teach you how to fix your problem, because your always going to run into this every time you create a new SQL Server, no matter what brand it is.
CONNECT to table in the WebDev - OK
CONNECT to table in IIS - OK
UPDATE table - OK
SELECT from table - Fails
[Possible Solutions]
Double check your connection string
http://www.connectionstrings.com/sql-server-2012[connection string^]
In the WebDev [F5], security is relaxed, so connecting to a SQL Server on your development computer is easier.
Server=.\SQLExpress ;Database=myDataBase ;Trusted_Connection=True;
But in a production enviroment, if your SQL server is remote, and your not running in a windows domain, you should use SQL Authentication, which is a SQL user account just for that tablespace, and secure password. When you ran the setup for SQL Server, you had a choice for Windows Auth or Mixed Mode, you need Mixed Mode for web apps, well it's just easier to start with, and is pretty secure with strong passwords.
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
Next, check your tablespace permissions, your SQL user must be able to CONNECT, SELECT, UPDATE at the minimum. A tablespace is the database name in SQL Server.
Use a program like EMS SQL Manager Lite,to open your table, and use the SQL Tool to write a simple query, and execute it. The program will print the actual server response, which is the error message that caused the failure. In asp.net, you have to capture that error using catch.
SELECT COUNT(*) FROM schema.tablename WHERE accountName = 'testName'
Check your results, you should get a value of 1
If that all works, write a function that does the same thing, and walk through it to make sure you get the same value in your project.
Now if that works fine, the error is now isolated down to your login program. You'll need to walk through the program code using F5 and make a break point using F9, and step through the database code using F11, examine the username and password buffers all the way through the journey, and make sure that the values are valid right up to the database execute query, and then check for any error messages.
Basically I think your either writing or reading bad data, or your user does not have permission to read the data.
If you bound the wizard control to a table, There might be a mistake somewhere, so you have to narrow it down.
[edit]
It doesn't matter that you have 2 databases to anyone but you. You have to fix the first database of choice, and when that is fixed, fix the second one, then both will work correctly.
|
|
|
|
|
Hello and thank you again!
Well the problem got fixed somehow, but i didn't change anything regarding the database permissions. What i changed was the below properties of my CreateUserWizard control
From
LoginCreatedUser="true" DisableCreatedUser="false"
To
LoginCreatedUser="false" DisableCreatedUser="true"
That seems to fixed the problem, but not completely. I can log in and authenticate all the registered users that exist in my membership database, except the first user i registered. That one can not be authenticated, and i don't understand why, since all the others can be authenticated just fine.
Thank you again,
TheS@int
|
|
|
|
|
That seems strange
The example code seems to represent that when the create user wizard runs and completes, it will login the user automatically.
So it looks like your problem is that the user is being disabled after creation. So if you login, you get a false flag saying login failed, when login was successful, but the account is disabled, so it's a fail.
You need to edit the table and toggle all the users to non-disabled, I think it should be
LoginCreatedUser="true" DisableCreatedUser="true"
|
|
|
|
|