Closing a Database connection

  • Thread starter Thread starter id10t error
  • Start date Start date
I

id10t error

I have the code below. I am running an Rf application and trying to
get multiple scanners to work at the same time. I put in a mutex
before this class is called. The problem is the first time the second
scan that goes through the following code gets an error. I even tried
to put in a 10 second wait to mutex to give the first scan plenty of
time to clear the class. Is there a way to clear the connection string
that I am not doing?

Public Function Firstrecord(ByVal userid As String, ByVal
programid As String)
Dim test As String = 0
'This will be used to store the date in number format
Dim todaynumber As String
' If works delete
'Dim b As String = DateTime.Now.ToString("yyyy/MM/dd
hh:mm:ss")
'Gets current time
Dim currenttime As String = DateTime.Now.ToString("HHmmss")
'sets number scan to 000 so for reports we know this is a
starting record
Dim numberscan As String = "000"
'This calls the get today number function and gets todays date
in number format
todaynumber = gettodaynumberfunc()
'Gets the store number from the Web Config file
Dim storenumber As String =
ConfigurationManager.AppSettings.Get("storenumber")
'This is used to setup the connection string to write the
record
Dim TPSupdate As New Data.Odbc.OdbcConnection()
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()
TPSupdate.Close()
Return test
End Function
 
The problem is the first time the second
scan that goes through the following code gets an error.

Please never talk about an error without telling us what it is (and the
exact line where it happens). The error message is the very first debugging
tool to use...

Not sure but if an class expose a dispose/close method always call it (here
insertCmd is not disposed) but this is a guess as we basically have no
information about what happens...
 
Please never talk about an error without telling us what it is (and the
exact line where it happens). The error message is the very first debugging
tool to use...

Not sure but if an class expose a dispose/close method always call it (here
insertCmd is not disposed) but this is a guess as we basically have no
information about what happens...

The second scanner gets the error message Sever application
Unavailable. The line of code giving me the problem is the insert
command.
 
Strange, it looks rather like an ASP.NET error message rather an ODBC error
:
http://www.google.com/search?hl=en-us&q="server+application+unavailable"&meta=

I would try to simplify the code to find out if it is caused by ODBC or the
mutex. For now I would rather guess a mutex issue as it seems an ASP.NET
side problem. Also have you tried to dispose the OdbcCommand ?

BTW you posted at east in two groups and now each of those threads evolves
separately. It would be best to post a message to one of those threads
asking to continue in the other group so that those who are trying to help
don't duplicate their efforts or don't miss the info you provide in the
other thread...

At least you new see a real life example of why posting to multiple groups
is bad ;-)
 
Hello,

I don't want to be a wise guy, but this table you are inserting a record in,
does it have a primary key? Because if there is a unique constraint on the
first field (Numberscan), you are bound to have an error when inserting a
second record. Perhaps a bit more info on this table would help.

Baldwin
 
Strange, it looks rather like an ASP.NET error message rather an ODBC error
:http://www.google.com/search?hl=en-us&q="server+application+unavail...

I would try to simplify the code to find out if it is caused by ODBC or the
mutex. For now I would rather guess a mutex issue as it seems an ASP.NET
side problem. Also have you tried to dispose the OdbcCommand ?

BTW you posted at east in two groups and now each of those threads evolves
separately. It would be best to post a message to one of those threads
asking to continue in the other group so that those who are trying to help
don't duplicate their efforts or don't miss the info you provide in the
other thread...

At least you new see a real life example of why posting to multiple groups
is bad ;-)

It is caused by the odbc. I tried to add the mutex to fix the problem.
 
Hello,

I don't want to be a wise guy, but this table you are inserting a record in,
does it have a primary key? Because if there is a unique constraint on the
first field (Numberscan), you are bound to have an error when inserting a
second record. Perhaps a bit more info on this table would help.

Baldwin

"id10t error" <[email protected]> schreef in bericht




- Show quoted text -

The primary key is the sku. This tables is for tracking productivity.
When the user first enters a program we write the a record. Then each
time there is a productive scan we wirte a reocrd to this file
 
So I would drop the mutex. It would be really surprising to need this to use
a db !!! It"s likely much better to fix the source problem rather than to
add such a desperate workaround...

Have you tried to dispose all objects as previously suggested ? Are you sure
this is a multi user database ? What if you try in a Windows app ?

What if you try the same code with another DB engine (if you have one)...

--
Patrice


"id10t error" <[email protected]> a écrit dans le message de
Strange, it looks rather like an ASP.NET error message rather an ODBC
error
:http://www.google.com/search?hl=en-us&q="server+application+unavail...

I would try to simplify the code to find out if it is caused by ODBC or
the
mutex. For now I would rather guess a mutex issue as it seems an ASP.NET
side problem. Also have you tried to dispose the OdbcCommand ?

BTW you posted at east in two groups and now each of those threads evolves
separately. It would be best to post a message to one of those threads
asking to continue in the other group so that those who are trying to help
don't duplicate their efforts or don't miss the info you provide in the
other thread...

At least you new see a real life example of why posting to multiple groups
is bad ;-)

It is caused by the odbc. I tried to add the mutex to fix the problem.
 
Back
Top