How to control a login?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all!

I'm working on a windows app, using SQL for my databse. I have a table
named "user id". There are 50 user numbers, ranging from 1-50. The numbers
are actually the login. no password. I would like to have a user sit down at
a computer, hit a button and go. I need the computer to be logged in from
the list of 50 number. If number 34 is taken for example, it continues to
look for a free number, until it finds one, then logs in.

Any ideas on what is the best way to approach this?

Thanks!!

Rudy
 
That is this number is just used to track the user the time of its session ?
Any reason for not using the usual session mechanism ?

Patrice
 
Hi Rudy,
I am not sure about this, but since you are using a windows app you
might not be connected to your SQL Server over the whole application
life cycle. I would simply add a new column to your users table called
*locked* or whatever. As soon as a client connects to your DB you get
the highest ID which is not locked.
Like
Select Max(userID) from users where locked = false
You apply this ID to the client.

Now, you have to make sure that when the client closed the app he frees
the ID for other users.

You can catch the close event of the main form and set the locked state
of the user ID back to false.

Maybe you have to add additional mechanisms to ensure that users are
unlocked when the app crashes...

Kind regards
Alex



http://www.flashshop.info
 
Hi Patrice and Alex!

Great suggestions! Alex, I was kind of thinking of doing waht you said, but
you have a better approach. I also thought about just creating a view for
each session. and deleting the view when user log out.

Patrice, I never heard of the session mechanism, of course I am new at this.
I'll look into it.

Thanks for the advice!!!!

Rudy
 
Just disregard my previous message. It doesn't apply to Windows application
and I wrongly thought it was a web group or something else short circuited
in my brain...

Sorry for the useless post...

Patrice



--
 
Hi Alex,
Thanks again for your idea! I put it to work, and I think I almost got it,
just a little bump. Here is the store proc that I have.
CREATE PROCEDURE [dbo].[max tableid] AS
SELECT MAX(TableID) AS Expr1
FROM TableID
WHERE (Inuse =0)
GO
My table"tableID", has a tableid col, and a Inuse col. my tableID is set
from 1- 5. my inuse is a bit, 1 or 0. 1 the table is in use, 0 the table is
free.
Here is a snippet of my code.
cmdLog = New SqlCommand("Max TableID", conLog)
cmdLog.CommandType = CommandType.StoredProcedure
TableIDReturn = cmdLog.Parameters.Add("ReturnValue", SqlDbType.Int)
TableIDReturn.Direction = ParameterDirection.ReturnValue

conLog.Open()
cmdLog.ExecuteNonQuery()

intTableID = cmdLog.Parameters("ReturnValue").Value
If intTableID <= 5 Then
myMainfrm.Show()
Else : intTableID = 0
MessageBox.Show("Sorry")
conLog.Close()
End If
My question is how can I have my "if"command select only from 1 to 5, and if
nothing shows up in the col, if all the tables were in use, that value = 0.

Thanks again for your help!
 
Hi Rudy,

the proc returns DBNull if no record found.
So you can do:

if cmdLog.Parameters("ReturnValue").Value = System.DBNull.Value Then
'no go

Best regards
Alex

- Alexander Rauser

http://www.flashshop.info
Hi Alex,
Thanks again for your idea! I put it to work, and I think I almost got it,
just a little bump. Here is the store proc that I have.
CREATE PROCEDURE [dbo].[max tableid] AS
SELECT MAX(TableID) AS Expr1
FROM TableID
WHERE (Inuse =0)
GO
My table"tableID", has a tableid col, and a Inuse col. my tableID is set
from 1- 5. my inuse is a bit, 1 or 0. 1 the table is in use, 0 the table is
free.
Here is a snippet of my code.
cmdLog = New SqlCommand("Max TableID", conLog)
cmdLog.CommandType = CommandType.StoredProcedure
TableIDReturn = cmdLog.Parameters.Add("ReturnValue", SqlDbType.Int)
TableIDReturn.Direction = ParameterDirection.ReturnValue

conLog.Open()
cmdLog.ExecuteNonQuery()

intTableID = cmdLog.Parameters("ReturnValue").Value
If intTableID <= 5 Then
myMainfrm.Show()
Else : intTableID = 0
MessageBox.Show("Sorry")
conLog.Close()
End If
My question is how can I have my "if"command select only from 1 to 5, and if
nothing shows up in the col, if all the tables were in use, that value = 0.

Thanks again for your help!

:

Hi Rudy,
I am not sure about this, but since you are using a windows app you
might not be connected to your SQL Server over the whole application
life cycle. I would simply add a new column to your users table called
*locked* or whatever. As soon as a client connects to your DB you get
the highest ID which is not locked.
Like
Select Max(userID) from users where locked = false
You apply this ID to the client.

Now, you have to make sure that when the client closed the app he frees
the ID for other users.

You can catch the close event of the main form and set the locked state
of the user ID back to false.

Maybe you have to add additional mechanisms to ensure that users are
unlocked when the app crashes...

Kind regards
Alex



http://www.flashshop.info
 

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

Back
Top