Jump to content

azizalm

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by azizalm

  1. Hello, This is Sanjeev(Senior of Bhushan, using his ID)According to ASPNETGUY, the solution to the current problem seems so. But then other way to check around is to see if the MSACCESS file is openede by any early connection or OPENED manually and did not close while in a Query Mode. If so then please close the MSACCESS file and delete the .LDB file (Locking) so that  it releases all the keys.Each time you connect, please write the IDISPOSE function for the class to close all the connections, if you forget to close it at the time when u have opened the connection.

    This is the code i Use:Dim the_user As OdbcDataReaderDim myQuery As String = "Select count(*) from users where user_name='" & CStr(username) & "'"Dim myConnection As New OdbcConnection(conn.get_dsn)Dim myCommand As New OdbcCommand(myQuery, myConnection)myConnection.Open()'then the use of this OdbcDataReaderbut i can't run another query know else if i cancel the OdbcCommand and the OdbcDataReaderlike this:the_user.Close()myCommand.Cancel()then i can run another query.and at the end i close the connection:myConnection.Close()My question is like That :How i can run query in a loop of another query without the exception i got.
  2. this cauld is make troubles.Private dbread Private con As OdbcConnection Private comm As OdbcCommand 'function for opening connection and geting query result Function initConnection(ByVal sql As String) ' make sure every thing is closed On Error Resume Next comm = Nothing con.Close() con = Nothing On Error GoTo 0 'open the connection Dim conn As New Connections con = New OdbcConnection(conn.get_dsn()) con.Open() 'execute th sql and assign value to dbread comm = New OdbcCommand(sql, con) dbread = comm.ExecuteReader() Return dbread End Function 'function to close a connection that opened in previos function Function closeConnection() 'after using connection by the initconnection() function the 'closeconnection is the 'function that deal with closeing connection and odbcommand Try comm = Nothing 'set the odbcommand as nothing con.Close() 'close the odbconnections con = Nothing 'set the odbconnection as Nothing Catch ex As Exception End Try End Function '********************************************************************************

  3. your closeConnection function only disposes the command are you calleing your destroy function everytime you call the closeConnection function???your destroy function is the function that is actually closing the connection not closeConnection.Why did you write a class for this stuff, it only takes a few lines anyways.

    The function I called to close the connection and destroy is the second one:closeConnection()I made it in class because a mudale in a static and class in publicTherefor i make a class and second is my code is correct because it's make a trouble to me i got the follow:File unKnown or file in use.Cauld you help me?
  4. Please post your code...it sounds like the connections and objects are not being closed/released properly.

    This is the class of the connection (vb.net code as you can see):Imports System.Data.OdbcPublic Class Connections '***************************************************************************** '**************************************************************' ' this is the variables for every connection and data reader. ' ' dberad is as a recordset ' ' con is for creating odbconnection ' ' comm is the odbcommand. ' '**************************************************************' Dim dbread Dim con As OdbcConnection Dim comm As OdbcCommand 'Constructor in this case no need 'function for opening connection and geting query result Function openConnection() ' make sure every thing is closed On Error Resume Next comm = Nothing 'con.Close() 'con = Nothing On Error GoTo 0 'open the connection con = New OdbcConnection("DSN=newBios") con.Open() End Function Function initConnection(ByVal sql As String) 'execute th sql and assign value to dbread comm = New OdbcCommand(sql, con) dbread = comm.ExecuteReader() Return dbread End Function 'function to close a connection that opened in previos function Function closeConnection() 'after using connection by the initconnection() function the 'closeconnection is the 'function that deal with closeing connection and odbcommand Try comm = Nothing 'set the odbcommand as nothing Catch ex As Exception End Try End Function Function destroy() Try con.Close() 'close the odbconnections con = Nothing 'set the odbconnection as Nothing Catch ex As Exception End Try End Function '********************************************************************************End Class
  5. I tried to use the oop for the connections, i build a class ia called connections and i make functions in this class to open the connections and one to closein the one that i open the connection a i also send the query that i want to run.sometimes i got exception that the file is alerady in use and that the dsn (unknown filename)If someone can help me i'll be gratefull.

×
×
  • Create New...