azizalm
-
Posts
5 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by azizalm
-
-
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 '********************************************************************************
-
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?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. -
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 ClassPlease post your code...it sounds like the connections and objects are not being closed/released properly. -
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.
ADO.Net
in .NET
Posted