Using Access Database as Membership source

J

James

Hi

I am quite new to membership and security etc. I have a large Access DB and
want to create a special section on a website for some of the members in the
database.

I have looked how to do this and have found about 10 sites, all with
different ways to do this. I have tried all but none work. The code I have
got closest to working is:

Web.Config:
<system.web>
<authentication mode="Forms"/>
<membership
defaultProvider="AccessMembershipProvider" >
<providers>
<add name="AccessMembershipProvider"
type="AccessMembershipProvider"
requiresQuestionAndAnswer="true"
connectionString="Provider=Microsoft.Jet.
OLEDB.4.0;Data Source=C:\NewMembershipProvider\
App_Data\Members.mdb;Persist Security
Info=False" />
</providers>
</membership>
</system.web>



AccessMembershipProvider.vb:

Private connStr As String
Private comm As New OleDb.OleDbCommand

Private _requiresQuestionAndAnswer As Boolean
Private _minRequiredPasswordLength As Integer

Public Overrides Function ValidateUser( _
ByVal username As String, _
ByVal password As String) As Boolean

Dim conn As New OleDb.OleDbConnection(connStr)
Try
conn.Open()
Dim sql As String = _
"Select * From Membership WHERE " & _
"username=@username AND password=@password"
Dim comm As New OleDb.OleDbCommand(sql, conn)
comm.Parameters.AddWithValue("@username", _
username)
comm.Parameters.AddWithValue("@password", _
password)
Dim reader As OleDb.OleDbDataReader = _
comm.ExecuteReader
If reader.HasRows Then
Return True
Else
Return False
End If
conn.Close()

Catch ex As Exception
Console.Write(ex.ToString)
Return False
End Try
End Function


That code comes up with errors about the OleDb.OleDbCommand saying I should
put Data. infront of it.

Is there anyone who can point me in the right direction on how to do this?

Many thanks

James
 
G

Guest

Hi

I am quite new to membership and security etc. I have a large Access DB and
want to create a special section on a website for some of the members in the
database.

I have looked how to do this and have found about 10 sites, all with
different ways to do this. I have tried all but none work. The code I have
got closest to working is:

Web.Config:
<system.web>
<authentication mode="Forms"/>
<membership
defaultProvider="AccessMembershipProvider" >
<providers>
<add name="AccessMembershipProvider"
type="AccessMembershipProvider"
requiresQuestionAndAnswer="true"
connectionString="Provider=Microsoft.Jet.
OLEDB.4.0;Data Source=C:\NewMembershipProvider\
App_Data\Members.mdb;Persist Security
Info=False" />
</providers>
</membership>
</system.web>

AccessMembershipProvider.vb:

Private connStr As String
Private comm As New OleDb.OleDbCommand

Private _requiresQuestionAndAnswer As Boolean
Private _minRequiredPasswordLength As Integer

Public Overrides Function ValidateUser( _
ByVal username As String, _
ByVal password As String) As Boolean

Dim conn As New OleDb.OleDbConnection(connStr)
Try
conn.Open()
Dim sql As String = _
"Select * From Membership WHERE " & _
"username=@username AND password=@password"
Dim comm As New OleDb.OleDbCommand(sql, conn)
comm.Parameters.AddWithValue("@username", _
username)
comm.Parameters.AddWithValue("@password", _
password)
Dim reader As OleDb.OleDbDataReader = _
comm.ExecuteReader
If reader.HasRows Then
Return True
Else
Return False
End If
conn.Close()

Catch ex As Exception
Console.Write(ex.ToString)
Return False
End Try
End Function

That code comes up with errors about the OleDb.OleDbCommand saying I should
put Data. infront of it.

Is there anyone who can point me in the right direction on how to do this?

Many thanks

James

James, your code is working for me.
Can you post here the complete error message?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top