Answered by:
Login page - MDB no connection

Question
-
User372570448 posted
Dear all,
I am building an application with login page as the landing page. The code below is supposed to retrieve information from an Access database. It will compare user name & password, if true then it will redirect to main page. When testing on localhost machine, the connection is successful. But when testing over a network using other computer, there seems to be no connection but no error. I have set all permission and security in IIS7 accordingly. Appreciate your help and comments. TQ.
Dim myPath As String myPath = Server.MapPath("olps.mdb") Dim connString As String connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";" Dim objConnection As OleDbConnection objConnection = New OleDbConnection(connString) 'Specify our SQL statement Dim strSQL As String = "SELECT Password, Nama FROM Staff WHERE Nama=?" 'Create the Command object Dim objCommand As OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) objCommand.Parameters.AddWithValue("?Nama", Trim(txtUserName.Text)) objConnection.Open() 'open the connection Dim strPassword As String = objCommand.ExecuteScalar() If strPassword = txtPassword.Text Then lblMessage.Text = "Login successful" Session("User") = txtUserName.Text Response.Redirect("main.aspx") Else lblMessage.Text = "Login fail" End If
Monday, April 26, 2010 10:30 PM
Answers
-
User-1199946673 posted
Let me go through your code from top to bottom. First of all you need to put the mdb file in the App_Data folder, because when you place it inside the root it can be downloaded directly (if someone would enter www.yourdomain.com/olps.mdb)
Also, you need to give the ASP.NET user Modify rights the the folder where the mdb file is in:
http://www.mikesdotnetting.com/Article/74/Solving-the-Operation-Must-Use-An-Updateable-Query-error
Then you're using password as a fieldname, but this is a reserved word in Jet so it should be enclosed in brackets. And instead of retrieving the password I would enter both the username and password and retrieve the amount of records:
SELECT count(*) FROM Staff WHERE nama = ? AND [password] = ?
Off course don't forget to pprovide the password as a parameter...
http://www.mikesdotnetting.com/Article/75/Simple-Login-and-Redirect-for-ASP.NET-and-Access
ANd finally, instead of designing you're own security system, you could consider to use the build in membership provider:
http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=404
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 27, 2010 3:36 AM
All replies
-
User-821857111 posted
What makes you think the problem is with the connection?
Tuesday, April 27, 2010 2:35 AM -
User-1199946673 posted
Let me go through your code from top to bottom. First of all you need to put the mdb file in the App_Data folder, because when you place it inside the root it can be downloaded directly (if someone would enter www.yourdomain.com/olps.mdb)
Also, you need to give the ASP.NET user Modify rights the the folder where the mdb file is in:
http://www.mikesdotnetting.com/Article/74/Solving-the-Operation-Must-Use-An-Updateable-Query-error
Then you're using password as a fieldname, but this is a reserved word in Jet so it should be enclosed in brackets. And instead of retrieving the password I would enter both the username and password and retrieve the amount of records:
SELECT count(*) FROM Staff WHERE nama = ? AND [password] = ?
Off course don't forget to pprovide the password as a parameter...
http://www.mikesdotnetting.com/Article/75/Simple-Login-and-Redirect-for-ASP.NET-and-Access
ANd finally, instead of designing you're own security system, you could consider to use the build in membership provider:
http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=404
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 27, 2010 3:36 AM -
User372570448 posted
Problem solved!! Thanks hans_v for the help
Sunday, May 2, 2010 6:52 AM