Click to See Complete Forum and Search --> : username and password -access database


elik
March 24th, 2001, 03:18 AM
hello, Im having problem with accessing Access DB with username and password, I used an sql statement but it doesnt work...do you know the code to enter to A Database with username and password??

this is the code i wrote:

Private Sub Form_Load()
' connecting the DB and the table

strFileName = App.Path & "\mydatabase.mdb"
Set db = OpenDatabase(strFileName)
Set rs_lgn = db.OpenRecordset("login")
pswrd = rs_lgn![password]
usrnme = rs_lgn![UserName]

End Sub

and on the click button i wrote:
sqlstr = "SELECT * FROM rs_lgn WHERE usrnme =" & username_inpt_local & "AND pswrd = " & password_inpt_local

'Set rs_lgn_true = db.OpenRecordset("sqlstr")

and so on.. but it doesnt work..
thank you


Eli

Robert Moy
March 24th, 2001, 06:33 PM
Hello elik:

I would access ADO. To do this, first go to Project and then Components and check Microsoft ADO. Then select Microsoft OLE for DB Provider for Oracle or SQL Provider. Next type this line of code

Adodc1.ConnectionString = "Provider=MSDAORA. 1;Password=" & Text2.Text & ";User ID=" & Text1.Text & ";Persist Security Info=True"
Adodc1.CommandType = adCmdUnknown

If you are using home computer or personal computer which I am in. You need to add server if you are networked.

Good Luck

Iouri
March 24th, 2001, 08:43 PM
'connection to secure database
Dim Cnn As ADODB.Connection
Dim Rst As ADODB.Recordset

'In the place where you want to establish your connection

Dim strConnect As String
Set Cnn = New ADODB.Connection

'Substitute your own User IDs, Password, Data Source, and System
'database in the connection string below
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=MyPassword;User ID=Administrator;" & _
"Data Source=C:\AccessDBs\DB1.mdb;" & _
"Persist Security Info=True;"

With Cnn
.CursorLocation = adUseClient
.Open strConnect
End With

Set Rst = New ADODB.Recordset
Rst.ActiveConnection = Cnn

Iouri Boutchkine
iouri@hotsheet.com

coolbiz
March 24th, 2001, 09:08 PM
Elik,

It looks like you have your own table which stores the USERNAME and PASSWORD. Am I right? If so, it seems that your SQL statement is not really right.

Commonly, USERNAME and PASSWORD fields are STRING type and you've your query:

sqlstr = "SELECT * FROM rs_lgn WHERE usrnme =" & username_inpt_local & "AND pswrd = " & password_inpt_local




I think you're missing the single quote (') marks to denote that the field data is a STRING type. The SQL query should look like this:

sqlstr = "SELECT * FROM rs_lgn WHERE usrnme ='" & username_inpt_local & "' AND pswrd = '" & password_inpt_local & "'"




Hope this helps,
-Cool Bizs