.net - Error Help: There is already an open DataReader associated with this Command which must be closed first. -
i'm having error in part of code , i'm still unable figure out solution it
error stats:
executereader requires open , available connection. connection's current state open.
with source code in:
line 144: .commandtype = commandtype.text
line 145: .connection = cn
line 146: dr = .executereader
line 147: end
line 148:
the code is:
public function getdbfield(byval query string, byval field string) string 'abriendo la conexion la base de datos sqlconnect() dim cmd new sqlcommand dim result string = "" dim dr sqldatareader dr = nothing 'ejecutando el lector de try cmd .commandtext = query .commandtype = commandtype.text .connection = cn dr = .executereader end catch ex sqlexception showalertmessage(ex.message) getdbfield = nothing exit function end try 'escribiendo en una variable de texto try if dr.hasrows end if while dr.read if isdbnull(dr(field).tostring) = true result = nothing else result = dr(field).tostring end if end while catch ex sqlexception showalertmessage(ex.message) getdbfield = nothing exit function end try 'cerrando la conexion de bd sqldisconnect() getdbfield = result end function
really in need of kind of help
in replay last question code in vb page in app_code
#region " variables globales" public db string = "repuestosdr" 'public cnstr string = "driver={sql server native client 10.0};server=localhost;database=" & db & ";uid=crivera;pwd=crivera;" public cnstr string = configurationmanager.connectionstrings("suoodconnection").connectionstring '"driver={sql server};server=repuestosdr.db.10580944.hostedresource.com;database=" & db & ";uid=" & db & ";pwd=r34llyh4rd!;port=1433;" public logged boolean = false public qry string public msg new msgboxresult public ds new dataset public dt new datatable public dr sqldatareader public cn new sqlconnection() public da new sqldataadapter public cmd sqlcommand #end region
for connection:
#region " connection" public function sqlconnect(optional byval mypage page = nothing) boolean try if cn.state = connectionstate.closed cn .connectionstring = cnstr .open() end end if catch myerror exception showalertmessage("error connecting database" & chr(13) & myerror.message) sqlconnect = false end try sqlconnect = true end function
Comments
Post a Comment