Operation is not allowed when the object is closed

31/08/2004 - 05:34 por leon | Informe spam
saludos listeros.

Estoy obteniendo este error cuando trato de correr el siguiente codigo.
"Operation is not allowed when the object is closed"

Solo les voy a mostrar el pedazo donde me esta sacando el error, lo demas
lo omití porque no es necesario, como cerrar la conexion y los recordset.

las consultas corren y ejecutan bien.
El error ocurre en esta linea:
esta cinco lineas antes del final:

"if rst2.EOF = false then"



dim strMaxInmueble

'se crean dos rs, rst = select a tlbBienes
' strMax = para obtener el maximo Inmueble
set rst = Server.CreateObject("ADODB.Recordset")
set rst2 = Server.CreateObject("ADODB.Recordset")
set rstMax = Server.CreateObject("ADODB.Recordset")


'Se busca el consecutivo para el negocio
strSQL = "SELECT strNumeroInmueble AS Ninmueble" & _
" FROM tblBienes"

rst.Open strSQL, strRutaConexion
if rst.EOF = true then
strNumeroInmueble = mid(Trim(SessionIdRegional),1,2) & "0001"
else
'ahora obtenemos el máximo número del negocio
strSQL = "SELECT
Max(CLng(Mid(strNumeroInmueble,Len([strNumeroInmueble])-3,Len([strNumeroInmu
eble])))) AS Ninmueble" & _
" FROM tblBienes"

rstMax.Open strSQL, strRutaConexion
strMaxInmueble = rstMax.Fields("Ninmueble")
'aumentamos en 1 el negocio
strMaxInmueble = CLng(strMaxInmueble) + 1
'necesitamos concatenar los ceros a la izquierda
if len(strMaxInmueble) = 1 then
strMaxInmueble = "000" & strMaxInmueble
else
if len(strMaxInmueble) = 2 then
strMaxInmueble = "00" & strMaxInmueble
else
if len(strMaxInmueble) = 3 then
strMaxInmueble = "0" & strMaxInmueble
end if
end if
end if
'concatenamos todo para obtener el número negocio final
strNumeroInmueble = mid(Trim(SessionIdRegional),1,2) & strMaxInmueble
end if

strSQL = ""
strSQL = "INSERT INTO tblBienes ( strNumeroInmueble, " & _
" strIdRegional, strNumeroNegocio, strIdTipoInmueble," & _
" bytGrupoInmueble, strEstadoBien, strCuentaConavi," & _
" dblValorConavi, strIdPerito, dblValorAvaluo, dblValorGastos," & _
" strLocalizacion, strUrbanizacion, strMunicipio, strBarrio," & _
" strIdEstrato, lngArea, strMatriculaIn, strIdPiso, " & _
" strIdMuro, strIdTecho, strIdCocina, bytNumeroAlcobas, " & varCampos &
" )" & _
" VALUES (" & strNumeroInmueble & ", " & _
" " & strIdRegional & ", " & strNumeroNegocio & ", '" &
strIdTipoInmueble & "'," & _
" '" & bytGrupoInmueble & "', " & strEstadoBien & ", " &
strCuentaConavi & ", " & _
" " & dblValorConavi & ", '" & strIdPerito & "', " & dblValorAvaluo & ",
" & dblValorGastos & ", " & _
" '" & strLocalizacion & "', '" & strUrbanizacion & "', '" &
strMunicipio & "', '" & strBarrio & "', " & _
" '" & strIdEstrato & "', " & lngArea & ", '" & strMatriculaIn & "', '"
& strIdPiso & "', " & _
" '" & strIdMuro & "', '" & strIdTecho & "', '" & strIdCocina & "', " &
bytNumeroAlcobas & ", " & varValores & ")"

objConx.Execute(strSQL)

'Si el negocio tiene asociado un Bien y una Obligacion, entonces
' se coloca el campo strEstadoNeg de la tabla tblNegocios en 2 Contabilizado
strSQL = "SELECT tblNegocios.strNumeroNegocio, tblNegocios.strEstadoNeg" &
_
"FROM (tblNegocios INNER JOIN tblBienes ON
tblNegocios.strNumeroNegocio" & _
" = tblBienes.strNumeroNegocio) INNER JOIN tblObligaciones ON
tblNegocios.strNumeroNegocio" & _
" = tblObligaciones.strNumeroNegocio" & _
" WHERE tblNegocios.strEstadoNeg = '" & strNumeroNegocio & "'"


objConx.Open strRutaConexion
rst2.Open strSQL, strRutaConexion
if rst2.EOF = false then
strSQL = "UPDATE tblNegocios SET tblNegocios.strEstadoNeg = 2" & _
" WHERE strNumeroNegocio = '" & strNumeroNegocio & "'"
objConx.Execute(strSQL)
end if


De antemano os agradezco

leon

Preguntas similare

Leer las respuestas

#11 leon
01/09/2004 - 16:02 | Informe spam
Ok, muchísimas gracias, valiosisima ayuda, voy a cambiarlo.

Saludos.

leon.




"Sashka" wrote in message
news:
Lo que te dije en el post anterior debes usar conexiones
explícitasen
lugar de pasarle la cadena de conexión (conexión implícita) como lo
haces..
rst2.Open strSQL, strRutaConexion

Debes pasarle el objecto connection...(conexion explícita)

strRutaConexion = "la cadena de conexion"
Set objConx = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")
objConx.Open strProvider
SQL= "el sql que necesitas"
RS.Open SQL, ObjConx
...
...
...
RS.close
set RS = nothing
objConX.close
Set objConx = nothing


"leon" escribió en el mensaje
news:
> Hola Sashka, el error era una conexion que ya tenia abierta mas arriba,


al
> fin lo encontré.
> Os abradezco por la grandiosa ayuda.
>
> Ahora Sashka, ya que me hablas de conexiones implicitas, y que creo las
> estoy haciendo mal,
> cual es la forma correctade hacerlo?
>
> saludos,
>
> leon.
>
>
>
> "Sashka" wrote in message
> news:#
> > Noooooooo... claro que tienes que pasarle la cadena del sql pero


en
> > lugar de pasarle la cadena de conexión como lo haces..
> > rst2.Open strSQL, strRutaConexion
> >
> > Debes pasarle el objecto connection...
> > strRutaConexion = "la cadena de conexion"
> > Set objConx = Server.CreateObject("ADODB.Connection")
> > Set RS = Server.CreateObject("ADODB.Recordset")
> > objConx.Open strProvider
> > SQL= "el sql que necesitas"
> > RS.Open SQL, ObjConx
> > ...
> > ...
> > ...
> > RS.close
> > set RS = nothing
> > objConX.close
> > Set objConx = nothing
> >
> > Sashka
> > MS MVP Access
> >
> > "leon" escribió en el mensaje
> > news:
> > > Sashka, o sea que lo que no debo hacer es cuando abra el recordset,
> > hacerlo
> > > de esta manera:
> > >
> > > rst2.Open strSQL
> > >
> > > Bueno por el momento, voy a probar lo que me dices haber como me va.
> > > De antemano te agredezco,
> > >
> > > leon.
> > >
> > >
> > > "Sashka" wrote in message
> > > news:ubn$
> > > > Yo no tengo claro como estás manejando el tema de la conexión...
> > > > Veo en el código esto:
> > > >
> > > > objConx.Execute(strSQL) ' la conexión está abierta si puedes hacer
> ésto
> > > >
> > > >
> > > > objConx.Open strRutaConexion ' estas abriendo una conexión abierta
> .
> > > > rst2.Open strSQL, strRutaConexion
> > > >
> > > > Por otro lado tu abres una conexión para ejecutar comandos
> > implícitos
> > > > con ella (es lo que hace el execute con una conexión) pero abres


los
> > > > recordsets con conexiones implícitas (practica nada buena)... es
decir
> > > > cuando tu pasas la cadena de conexión al open de un recordset, en
> lugar
> > de
> > > > pasarle la conexión... lo que haces es abrir una conexión


implícita
> que
> > no
> > > > se cierra hasta que cierras el recordset y lo seteas a nothing
> > > > Cómo no pones todo el código... puedo suponer que eso lo haces


otras
> > veces
> > > > más... así que lo que puede estar pasando es que no se abre el
> recordset
> > > > (rst2) debido a que no tienes más conexiones disponibles en el
> pool
> > > >
> > > >
> > >
> >
>



http://support.microsoft.com/defaul...?scid=http://support.microsoft.com:
> 80/support/kb/articles/Q191/5/72.ASP&NoWebContent=1
> > > >
> > > > En todo caso ... ponle un on error resume next y verifica cual es


el
> > > > error...
> > > >
> > > > objConx.Open strRutaConexion ' estas abriendo una conexión abierta
> .
> > > > rst2.Open strSQL, strRutaConexion
> > > > if rst2.EOF = false then
> > > > if err = 0 then
> > > > strSQL = "UPDATE tblNegocios SET
> tblNegocios.strEstadoNeg
> > > > > > > 2" & _
> > > > " WHERE strNumeroNegocio = '" & strNumeroNegocio &
"'"
> > > > objConx.Execute(strSQL)
> > > > ELSE
> > > > Response.write err.description
> > > > End If
> > > > end if
> > > > On error goto 0
> > > >
> > > > Sashka
> > > > MS MVP Access
> > > >
> > > >
> > > >
> > > > "leon" escribió en el mensaje
> > > > news:
> > > > > Hola Franco, eso es lo que me parece estraño, porque la conexion
la
> > > cierro
> > > > a
> > > > > lo ultimo cuando hace todo, es mas en el codigo ni la puse


porque
no
> > lo
> > > > > creí interesante.
> > > > >
> > > > > Sigo en la busqueda de la solucion.
> > > > >
> > > > > Saludos.
> > > > >
> > > > > fausto.
> > > > >
> > > > >
> > > > > "Franco Figún" wrote in message
> > > > > news:
> > > > > > Me suena a que alomejor estas tratando de hacer la consultar o
> > > insertar
> > > > > > datos, ya habiendo cerrado la conexion, o el recordset...
> > > > > >
> > > > > > FF
> > > > > > www.francofigun.com.ar
> > > > > > www.microsofties.com.ar
> > > > > > Yahoo MSN:
> > > > > > ICQ: 314408886
> > > > > >
> > > > > > "leon" escribió en el mensaje
> > > > > > news:
> > > > > > > saludos listeros.
> > > > > > >
> > > > > > > Estoy obteniendo este error cuando trato de correr el
siguiente
> > > > codigo.
> > > > > > > "Operation is not allowed when the object is closed"
> > > > > > >
> > > > > > > Solo les voy a mostrar el pedazo donde me esta sacando el
error,
> > lo
> > > > > demas
> > > > > > > lo omití porque no es necesario, como cerrar la conexion y


los
> > > > > recordset.
> > > > > > >
> > > > > > > las consultas corren y ejecutan bien.
> > > > > > > El error ocurre en esta linea:
> > > > > > > esta cinco lineas antes del final:
> > > > > > >
> > > > > > > "if rst2.EOF = false then"
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > dim strMaxInmueble
> > > > > > >
> > > > > > > 'se crean dos rs, rst = select a tlbBienes
> > > > > > > ' strMax = para obtener el maximo Inmueble
> > > > > > > set rst = Server.CreateObject("ADODB.Recordset")
> > > > > > > set rst2 = Server.CreateObject("ADODB.Recordset")
> > > > > > > set rstMax = Server.CreateObject("ADODB.Recordset")
> > > > > > >
> > > > > > >
> > > > > > > 'Se busca el consecutivo para el negocio
> > > > > > > strSQL = "SELECT strNumeroInmueble AS Ninmueble" & _
> > > > > > > " FROM tblBienes"
> > > > > > >
> > > > > > > rst.Open strSQL, strRutaConexion
> > > > > > > if rst.EOF = true then
> > > > > > > strNumeroInmueble mid(Trim(SessionIdRegional),1,2)
&
> > > > "0001"
> > > > > > > else
> > > > > > > 'ahora obtenemos el máximo número del negocio
> > > > > > > strSQL = "SELECT
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>



Max(CLng(Mid(strNumeroInmueble,Len([strNumeroInmueble])-3,Len([strNumeroInmu
> > > > > > > eble])))) AS Ninmueble" & _
> > > > > > > " FROM tblBienes"
> > > > > > >
> > > > > > > rstMax.Open strSQL, strRutaConexion
> > > > > > > strMaxInmueble = rstMax.Fields("Ninmueble")
> > > > > > > 'aumentamos en 1 el negocio
> > > > > > > strMaxInmueble = CLng(strMaxInmueble) + 1
> > > > > > > 'necesitamos concatenar los ceros a la izquierda
> > > > > > > if len(strMaxInmueble) = 1 then
> > > > > > > strMaxInmueble = "000" & strMaxInmueble
> > > > > > > else
> > > > > > > if len(strMaxInmueble) = 2 then
> > > > > > > strMaxInmueble = "00" & strMaxInmueble
> > > > > > > else
> > > > > > > if len(strMaxInmueble) = 3 then
> > > > > > > strMaxInmueble = "0" & strMaxInmueble
> > > > > > > end if
> > > > > > > end if
> > > > > > > end if
> > > > > > > 'concatenamos todo para obtener el número negocio
> final
> > > > > > > strNumeroInmueble = mid(Trim(SessionIdRegional),1,2) &
> > > > > strMaxInmueble
> > > > > > > end if
> > > > > > >
> > > > > > > strSQL = ""
> > > > > > > strSQL = "INSERT INTO tblBienes ( strNumeroInmueble,


"
&
> _
> > > > > > > " strIdRegional, strNumeroNegocio, strIdTipoInmueble,"


&
_
> > > > > > > " bytGrupoInmueble, strEstadoBien, strCuentaConavi," &


_
> > > > > > > " dblValorConavi, strIdPerito, dblValorAvaluo,
> > dblValorGastos,"
> > > &
> > > > _
> > > > > > > " strLocalizacion, strUrbanizacion, strMunicipio,
> strBarrio,"
> > &
> > > _
> > > > > > > " strIdEstrato, lngArea, strMatriculaIn, strIdPiso, " &


_
> > > > > > > " strIdMuro, strIdTecho, strIdCocina, bytNumeroAlcobas,


"
&
> > > > > varCampos
> > > > > > &
> > > > > > > " )" & _
> > > > > > > " VALUES (" & strNumeroInmueble & ", " & _
> > > > > > > " " & strIdRegional & ", " & strNumeroNegocio & ", '" &
> > > > > > > strIdTipoInmueble & "'," & _
> > > > > > > " '" & bytGrupoInmueble & "', " & strEstadoBien & ", "


&
> > > > > > > strCuentaConavi & ", " & _
> > > > > > > " " & dblValorConavi & ", '" & strIdPerito & "', " &
> > > > dblValorAvaluo
> > > > > &
> > > > > > ",
> > > > > > > " & dblValorGastos & ", " & _
> > > > > > > " '" & strLocalizacion & "', '" & strUrbanizacion & "',
'"
> &
> > > > > > > strMunicipio & "', '" & strBarrio & "', " & _
> > > > > > > " '" & strIdEstrato & "', " & lngArea & ", '" &
> > strMatriculaIn
> > > &
> > > > > "',
> > > > > > '"
> > > > > > > & strIdPiso & "', " & _
> > > > > > > " '" & strIdMuro & "', '" & strIdTecho & "', '" &
> strIdCocina
> > &
> > > > "',
> > > > > "
> > > > > > &
> > > > > > > bytNumeroAlcobas & ", " & varValores & ")"
> > > > > > >
> > > > > > > objConx.Execute(strSQL)
> > > > > > >
> > > > > > > 'Si el negocio tiene asociado un Bien y una Obligacion,
> entonces
> > > > > > > ' se coloca el campo strEstadoNeg de la tabla tblNegocios


en
2
> > > > > > > > > Contabilizado
> > > > > > > strSQL = "SELECT tblNegocios.strNumeroNegocio,
> > > > > tblNegocios.strEstadoNeg"
> > > > > > &
> > > > > > > _
> > > > > > > "FROM (tblNegocios INNER JOIN tblBienes ON
> > > > > > > tblNegocios.strNumeroNegocio" & _
> > > > > > > " = tblBienes.strNumeroNegocio) INNER JOIN
tblObligaciones
> ON
> > > > > > > tblNegocios.strNumeroNegocio" & _
> > > > > > > " = tblObligaciones.strNumeroNegocio" & _
> > > > > > > " WHERE tblNegocios.strEstadoNeg = '" &


strNumeroNegocio
&
> > "'"
> > > > > > >
> > > > > > >
> > > > > > > objConx.Open strRutaConexion
> > > > > > > rst2.Open strSQL, strRutaConexion
> > > > > > > if rst2.EOF = false then
> > > > > > > strSQL = "UPDATE tblNegocios SET
> > tblNegocios.strEstadoNeg
> > > > > > > > 2"
> > > > > &
> > > > > > _
> > > > > > > " WHERE strNumeroNegocio = '" & strNumeroNegocio &


"'"
> > > > > > > objConx.Execute(strSQL)
> > > > > > > end if
> > > > > > >
> > > > > > >
> > > > > > > De antemano os agradezco
> > > > > > >
> > > > > > > leon
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
>
>
>
>


email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una pregunta AnteriorRespuesta Tengo una respuesta
Search Busqueda sugerida