Problem two users writing to same file

I

id10t error

Hello,

I am making a scanner application. I am having a problem when the
users are using two scanners at one and they try to write to the TPS
file at the same time. Here is my code. Is there anything i am doing
wrong. If two people scan at the same time the scanners will freeze
up.

TPSupdate.ConnectionString =
ConfigurationManager.AppSettings.Get("DSNEMPMST")
TPSupdate.ConnectionString =
ConfigurationManager.AppSettings.Get("EMPMSTconnection")
'Opens the connection to get data from TPS file
TPSupdate.Open()
'Declares an object of OdbcCommand Object to execute the
select statement
Dim insertCmd As New Data.Odbc.OdbcCommand()
'Sets the propertirs of the command object
insertCmd.Connection = TPSupdate
insertCmd.CommandTimeout = 1000
'This will setup the record to be inserted into the table
insertCmd.CommandText = "Insert into RFPRD
(Numberscan,storenum,programid,usernumber,datescanned,timescanned)
Values ('" & numberscan & "','" & storenumber & "','" & programid &
"'," & userid & "," & todaynumber & "," & currenttime & ")"
'This is the command that will insert the record into
RFPRD.tps
insertCmd.ExecuteNonQuery()
insertCmd.Dispose()
TPSupdate.Close()
TPSupdate.Dispose()
 
R

Rich P

Greetings,

You could try something similar to this idea: In a sql server table I
will have users (of my apps) read a table (which I call the InUse table)
which will contain at most only one row and one field before running a
process that is a single user process. If the table is empty then the
app writes the User's ID to the table and proceeds with the operation.
If another user tries to run the same operation with his/her params -
the app first reads this table. If the table is not empty then the app
informs this user that the process is currently in use and to try again
in a few minutes. When user1 has finished his/her operation - it
removes this user's ID from the InUse table and make it an the given
process available to the next user.

Your TPS file looks like some kind of database system. Is it a database
or just a file - a text file? It looks like you connect to this
datasource using ODBC.

Rich
 
T

Tom Shelton

Hello,

I am making a scanner application. I am having a problem when the
users are using two scanners at one and they try to write to the TPS
file at the same time. Here is my code. Is there anything i am doing
wrong. If two people scan at the same time the scanners will freeze
up.

TPSupdate.ConnectionString =
ConfigurationManager.AppSettings.Get("DSNEMPMST")
TPSupdate.ConnectionString =
ConfigurationManager.AppSettings.Get("EMPMSTconnection")
'Opens the connection to get data from TPS file
TPSupdate.Open()
'Declares an object of OdbcCommand Object to execute the
select statement
Dim insertCmd As New Data.Odbc.OdbcCommand()
'Sets the propertirs of the command object
insertCmd.Connection = TPSupdate
insertCmd.CommandTimeout = 1000
'This will setup the record to be inserted into the table
insertCmd.CommandText = "Insert into RFPRD
(Numberscan,storenum,programid,usernumber,datescanned,timescanned)
Values ('" & numberscan & "','" & storenumber & "','" & programid &
"'," & userid & "," & todaynumber & "," & currenttime & ")"
'This is the command that will insert the record into
RFPRD.tps
insertCmd.ExecuteNonQuery()
insertCmd.Dispose()
TPSupdate.Close()
TPSupdate.Dispose()

Sounds like you might want to use a mutex to make sure that they can't scan at
the same time...
 
I

id10t error

Greetings,

You could try something similar to this idea: In a sql server table I
will have users (of my apps) read a table (which I call the InUse table)
which will contain at most only one row and one field before running a
process that is a single user process.  If the table is empty then the
app writes the User's ID to the table and proceeds with the operation.
If another user tries to run the same operation with his/her params -
the app first reads this table.  If the table is not empty then the app
informs this user that the process is currently in use and to try again
in a few minutes.  When user1 has finished his/her operation - it
removes this user's ID from the InUse table and make it an the given
process available to the next user.

Your TPS file looks like some kind of database system.  Is it a database
or just a file - a text file?  It looks like you connect to this
datasource using ODBC.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
It is a database. I connect to a database file. I think writing to the
separate file will give me the same file contention problem I am
getting down. Its only when two users hit the file at the same time.
Won't that happen to any file?
 

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

Top