Closing connection

Discussion in 'ASP .Net' started by id10t error, Sep 14, 2009.

  1. id10t error

    id10t error Guest

    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
     
    id10t error, Sep 14, 2009
    #1
    1. Advertising

  2. id10t error <> wrote in news:c25e47bd-bd47-4320-bb97-
    :

    > 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
    >


    My first thought is try Dispose() on the connection to ensure it has
    been marked as finished.

    I do have a question about this, however:

    TPSupdate.ConnectionString =
    ConfigurationManager.AppSettings.Get("DSNEMPMST")
    TPSupdate.ConnectionString =
    ConfigurationManager.AppSettings.Get("EMPMSTconnection")

    Since you are not using the DSNEMPMST, why have it in code.

    What type of database are you using here? That may be another issue, as
    the closing of any lock files (Access, for example) could be an issue.
    If you can move from ODBC to OLEDB, you will see some perf improvement,
    which may help, if destroying a lock file is the issue.

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    My vacation and childhood cancer awareness site:
    http://www.crazycancertour.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Sep 14, 2009
    #2
    1. Advertising

  3. id10t error

    id10t error Guest

    On Sep 14, 10:38 am, "Gregory A. Beamer"
    <> wrote:
    > id10t error <> wrote in news:c25e47bd-bd47-4320-bb97-
    > :
    >
    >
    >
    >
    >
    > > 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

    >
    > My first thought is try Dispose() on the connection to ensure it has
    > been marked as finished.
    >
    > I do have a question about this, however:
    >
    >         TPSupdate.ConnectionString =
    > ConfigurationManager.AppSettings.Get("DSNEMPMST")
    >         TPSupdate.ConnectionString =
    > ConfigurationManager.AppSettings.Get("EMPMSTconnection")
    >
    > Since you are not using the DSNEMPMST, why have it in code.
    >
    > What type of database are you using here? That may be another issue, as
    > the closing of any lock files (Access, for example) could be an issue.
    > If you can move from ODBC to OLEDB, you will see some perf improvement,
    > which may help, if destroying a lock file is the issue.
    >
    > Peace and Grace,
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog:http://gregorybeamer.spaces.live.com
    >
    > My vacation and childhood cancer awareness site:http://www.crazycancertour.com
    >
    > *******************************************
    > |      Think outside the box!             |
    > *******************************************- Hide quoted text -
    >
    > - Show quoted text -


    I am connecting to a TPS database. That is why i have to use a ODBC
    connection.
     
    id10t error, Sep 14, 2009
    #3
  4. id10t error

    Patrice Guest

    Hi again,

    In another group where you asked for help, I mentionned that telling us the
    exact error message as well as its location is considered as a best practice
    when asking for help about an error.

    Similarly it is considered best to avoid posting the same message separately
    in multiple groups (to avoid wasting the time of those who would try to help
    in a group, when the issue is already solved in another group).

    Thanks in advance...
    --
    Patrice
     
    Patrice, Sep 14, 2009
    #4
  5. id10t error <> wrote in
    news::


    > I am connecting to a TPS database. That is why i have to use a ODBC
    > connection.
    >


    Not familiar with this type of database. Does it create a lock file of some
    type? If so, the destruction of the lock file might be what is causing the
    issue.

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    My vacation and childhood cancer awareness site:
    http://www.crazycancertour.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Sep 14, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brent

    Closing database connection.

    Brent, Apr 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    355
    Brent
    Apr 3, 2004
  2. =?Utf-8?B?Vk1J?=

    Closing popup window when closing parent window?

    =?Utf-8?B?Vk1J?=, Feb 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    680
    Thomas Hansen
    Feb 15, 2007
  3. johnny
    Replies:
    1
    Views:
    823
    Jerry Hill
    Dec 8, 2006
  4. shmuel witman

    Connection timeout (connection closing after 100 sec )

    shmuel witman, Dec 4, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    925
    shmuel witman
    Dec 6, 2005
  5. thomas
    Replies:
    0
    Views:
    253
    thomas
    Oct 23, 2003
Loading...

Share This Page