Showing posts with label closed. Show all posts
Showing posts with label closed. Show all posts

Wednesday, March 7, 2012

operation not allowed when object is closed...

I have this stored procedure on SQL 2005:

USE [Eventlog]

GO

/****** Object: StoredProcedure [dbo].[SelectCustomerSoftwareLicenses] Script Date: 08/07/2007 16:56:32 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[SelectCustomerSoftwareLicenses]

(

@.CustomerID char(8)

)

AS

BEGIN

DECLARE @.Temp TABLE (SoftwareID int)

INSERT INTO @.Temp

SELECT SoftwareID FROM Workstations

JOIN WorkstationSoftware ON Workstations.WorkstationID = WorkstationSoftware.WorkstationID

WHERE Workstations.CustomerID = @.CustomerID

UNION ALL

SELECT SoftwareID FROM Notebooks

JOIN NotebookSoftware ON Notebooks.NotebookID = NotebookSoftware.NotebookID

WHERE Notebooks.CustomerID = @.CustomerID

UNION ALL

SELECT SoftwareID FROM Machines

JOIN MachinesSoftware ON Machines.MachineID = MachinesSoftware.MachineID

WHERE Machines.CustomerID = @.CustomerID

DECLARE @.SoftwareInstalls TABLE (rowid int identity(1,1), SoftwareID int, Installs int)

INSERT INTO @.SoftwareInstalls

SELECT SoftwareID, COUNT(*) AS Installs FROM @.Temp

GROUP BY SoftwareID

DECLARE @.rowid int

SET @.rowid = (SELECT COUNT(*) FROM @.SoftwareInstalls)

WHILE @.rowid > 0 BEGIN

UPDATE SoftwareLicenses

SET Installs = (SELECT Installs FROM @.SoftwareInstalls WHERE rowid = @.rowid)

WHERE SoftwareID = (SELECT SoftwareID FROM @.SoftwareInstalls WHERE rowid = @.rowid)

DELETE FROM @.SoftwareInstalls

WHERE rowid = @.rowid

SET @.rowid = (SELECT COUNT(*) FROM @.SoftwareInstalls)

END

SELECT SoftwareLicenses.SoftwareID, Software.Software, SoftwareLicenses.Licenses, SoftwareLicenses.Installs FROM SoftwareLicenses

JOIN Software ON SoftwareLicenses.SoftwareID = Software.SoftwareID

WHERE SoftwareLicenses.CustomerID = @.CustomerID

ORDER BY Software.Software

END

When i execute it in a Query in SQL Studio it works fine, but when i execute it from an ASP page, i get following error:

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

/administration/licenses_edit.asp, line 56

Here the conection:

Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.ConnectionTimeout = Session("ConnectionTimeout")
OBJdbConnection.CommandTimeout = Session("CommandTimeout")
OBJdbConnection.Open Session("ConnectionString")
Set SQLStmt = Server.CreateObject("ADODB.Command")
Set RS = Server.CreateObject("ADODB.Recordset")

SQLStmt.CommandText = "EXECUTE SelectCustomerSoftwareLicenses '" & Request("CustomerID") & "'"
SQLStmt.CommandType = 1
Set SQLStmt.ActiveConnection = OBJdbConnection
RS.Open SQLStmt
RS.Close

Can anyone help please?

It this because of the variable tables?

If I recall correctly, an ADODB recordset is not a disconnected object.

You must do your actions between the OPEN and CLOSE.

Are you using VB v6, or Access?

(.NET allows the use of disconnected data using a dataset -NOT a recordset.)

|||

I'm using VB v6 and SQL Server 2005

I am going through my recordset between the open and close.

I think the problem lies in the scope of the variable table in stored procedure, because if i remove that whole chunk with the variable tables, there are no problems.

I have made the script work in totally different way, so i haven't solved the problem, just worked around it Smile

But it would still be nice to know if it is the scope of the varible tables that is being exceeded, and how, if possible to avoid this...?

|||

Just add "set nocount on" as the first statement in your sproc and your problem should go away.

Code Snippet

ALTER PROCEDURE [dbo].[SelectCustomerSoftwareLicenses]

(

@.CustomerID char(8)

)

AS

set nocount on

BEGIN

DECLARE @.Temp TABLE (SoftwareID int)

INSERT INTO @.Temp

SELECT SoftwareID FROM Workstations

JOIN WorkstationSoftware ON Workstations.WorkstationID = WorkstationSoftware.WorkstationID

WHERE Workstations.CustomerID = @.CustomerID

UNION ALL

SELECT SoftwareID FROM Notebooks

JOIN NotebookSoftware ON Notebooks.NotebookID = NotebookSoftware.NotebookID

WHERE Notebooks.CustomerID = @.CustomerID

UNION ALL

SELECT SoftwareID FROM Machines

JOIN MachinesSoftware ON Machines.MachineID = MachinesSoftware.MachineID

WHERE Machines.CustomerID = @.CustomerID

DECLARE @.SoftwareInstalls TABLE (rowid int identity(1,1), SoftwareID int, Installs int)

INSERT INTO @.SoftwareInstalls

SELECT SoftwareID, COUNT(*) AS Installs FROM @.Temp

GROUP BY SoftwareID

DECLARE @.rowid int

SET @.rowid = (SELECT COUNT(*) FROM @.SoftwareInstalls)

WHILE @.rowid > 0 BEGIN

UPDATE SoftwareLicenses

SET Installs = (SELECT Installs FROM @.SoftwareInstalls WHERE rowid = @.rowid)

WHERE SoftwareID = (SELECT SoftwareID FROM @.SoftwareInstalls WHERE rowid = @.rowid)

DELETE FROM @.SoftwareInstalls

WHERE rowid = @.rowid

SET @.rowid = (SELECT COUNT(*) FROM @.SoftwareInstalls)

END

SELECT SoftwareLicenses.SoftwareID, Software.Software, SoftwareLicenses.Licenses, SoftwareLicenses.Installs FROM SoftwareLicenses

JOIN Software ON SoftwareLicenses.SoftwareID = Software.SoftwareID

WHERE SoftwareLicenses.CustomerID = @.CustomerID

ORDER BY Software.Software

END

|||add the following code before "RS.Open SQLStmt"

"Set RS.ActiveConnection = OBJdbConnection"|||

Yes. "SET NOCOUNT ON" will fix your issue. The recordset will not get the resultset from the procedures. Instead of the resultset, the Insert statement's feedback will go.

You can add the "SET NOCOUNT ON" on your sp at first line or you can use the bellow command text,

SQLStmt.CommandText = "SET NOCOUNT ON;EXECUTE SelectCustomerSoftwareLicenses '" & Request("CustomerID") & "'"

Operation is not allowed while the object is closed (was "Hmmm")

never seen this before, but I keep getting an error > "Operationg is not allowed while the object is closed" I thought maybe I was getting this due to an error in my stored procedure, however the procedure runs fine. Could this be an error in my procedure that it's just not catching? Or is it more likely to be in my VB code? Anyone know in general why this happens? Thanks.Yes this is sounds like an ADO error in your VB code. You are either trying to run a procedure against a closed connection object or you trying to access the data from a recordset object that has not been set or open.

Operation is not allowed when the object is closed...

First, let me apologize for not knowing where to post this question...I hope
I've found the proper forum.
Up until three days ago, we've had a native-windows application (dot net)
connecting to a SQL (2000) back-end working with absolutely no problems for
the better part of five years now. Unfortunately, now, upon launching the
client-side applications, we are receiving this error message:
Operation is not allowed when the object is closed.
And, of course, we have no one on staff that knows SQL any more.
Is there any way I can troubleshoot this issue and restore service to my
clients?
Thanx.This looks to me like a .NET error instead of a SQL Server error.
Linchi
"Steven Sinclair" wrote:
> First, let me apologize for not knowing where to post this question...I hope
> I've found the proper forum.
> Up until three days ago, we've had a native-windows application (dot net)
> connecting to a SQL (2000) back-end working with absolutely no problems for
> the better part of five years now. Unfortunately, now, upon launching the
> client-side applications, we are receiving this error message:
> Operation is not allowed when the object is closed.
> And, of course, we have no one on staff that knows SQL any more.
> Is there any way I can troubleshoot this issue and restore service to my
> clients?
> Thanx.|||Okay.
Is there a way I can determine that for sure?
Thanx.
"Linchi Shea" wrote:
> This looks to me like a .NET error instead of a SQL Server error.
> Linchi
> "Steven Sinclair" wrote:
> > First, let me apologize for not knowing where to post this question...I hope
> > I've found the proper forum.
> >
> > Up until three days ago, we've had a native-windows application (dot net)
> > connecting to a SQL (2000) back-end working with absolutely no problems for
> > the better part of five years now. Unfortunately, now, upon launching the
> > client-side applications, we are receiving this error message:
> >
> > Operation is not allowed when the object is closed.
> >
> > And, of course, we have no one on staff that knows SQL any more.
> >
> > Is there any way I can troubleshoot this issue and restore service to my
> > clients?
> >
> > Thanx.|||Is there more to the error message than that?|||Unfortunately, no. Just that message window with an [OK] button.
I'm thinking now, since I can access the DB directly, that it is a .Net
issue, not a DB issue.
Thanx.
"cappjr@.gmail.com" wrote:
> Is there more to the error message than that?
>|||Just Google for this error and you'll see lots of threads about this error
in various forums.
It looks like this is an error that occurs because of wrong coding... It's
not directly about SQL Server, it's about the codes in your app.
--
Ekrem Ã?nsoy
"Steven Sinclair" <StevenSinclair@.discussions.microsoft.com> wrote in
message news:F7E013EA-4A2F-4FB8-A1DF-B1A71A9AEB0A@.microsoft.com...
> First, let me apologize for not knowing where to post this question...I
> hope
> I've found the proper forum.
> Up until three days ago, we've had a native-windows application (dot net)
> connecting to a SQL (2000) back-end working with absolutely no problems
> for
> the better part of five years now. Unfortunately, now, upon launching the
> client-side applications, we are receiving this error message:
> Operation is not allowed when the object is closed.
> And, of course, we have no one on staff that knows SQL any more.
> Is there any way I can troubleshoot this issue and restore service to my
> clients?
> Thanx.|||Yes, I did find a whole lot of information relating to this error through
Google. However, unfortunately, we don't have access to any of the source
code. All we have to deal with is the SQL server and EXE applications that
connect to the SQL server.
Thanx.
"Ekrem Ã?nsoy" wrote:
> Just Google for this error and you'll see lots of threads about this error
> in various forums.
> It looks like this is an error that occurs because of wrong coding... It's
> not directly about SQL Server, it's about the codes in your app.
> --
> Ekrem Ã?nsoy
>
> "Steven Sinclair" <StevenSinclair@.discussions.microsoft.com> wrote in
> message news:F7E013EA-4A2F-4FB8-A1DF-B1A71A9AEB0A@.microsoft.com...
> > First, let me apologize for not knowing where to post this question...I
> > hope
> > I've found the proper forum.
> >
> > Up until three days ago, we've had a native-windows application (dot net)
> > connecting to a SQL (2000) back-end working with absolutely no problems
> > for
> > the better part of five years now. Unfortunately, now, upon launching the
> > client-side applications, we are receiving this error message:
> >
> > Operation is not allowed when the object is closed.
> >
> > And, of course, we have no one on staff that knows SQL any more.
> >
> > Is there any way I can troubleshoot this issue and restore service to my
> > clients?
> >
> > Thanx.
>|||I'd start by adding SET NOCOUNT ON to the relevant procedures.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Steven Sinclair" <StevenSinclair@.discussions.microsoft.com> wrote in message
news:F7E013EA-4A2F-4FB8-A1DF-B1A71A9AEB0A@.microsoft.com...
> First, let me apologize for not knowing where to post this question...I hope
> I've found the proper forum.
> Up until three days ago, we've had a native-windows application (dot net)
> connecting to a SQL (2000) back-end working with absolutely no problems for
> the better part of five years now. Unfortunately, now, upon launching the
> client-side applications, we are receiving this error message:
> Operation is not allowed when the object is closed.
> And, of course, we have no one on staff that knows SQL any more.
> Is there any way I can troubleshoot this issue and restore service to my
> clients?
> Thanx.|||> Operation is not allowed when the object is closed.
As the others have mentioned, this is an application error rather than a SQL
error. This error is often raised when the application tries to use an
object for data retrieval without first checking to ensure it is in a valid
state. My guess is that the application expects at least one row of data
but either no rows were returned or no results were returned at all.
Perhaps a recent data change introduced this error. I suggest you reproduce
the error with a Profiler trace running and examine the last SQL statements
executed on the connection. That might provide a clue in lieu of debugging
the application code.
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Steven Sinclair" <StevenSinclair@.discussions.microsoft.com> wrote in
message news:F7E013EA-4A2F-4FB8-A1DF-B1A71A9AEB0A@.microsoft.com...
> First, let me apologize for not knowing where to post this question...I
> hope
> I've found the proper forum.
> Up until three days ago, we've had a native-windows application (dot net)
> connecting to a SQL (2000) back-end working with absolutely no problems
> for
> the better part of five years now. Unfortunately, now, upon launching the
> client-side applications, we are receiving this error message:
> Operation is not allowed when the object is closed.
> And, of course, we have no one on staff that knows SQL any more.
> Is there any way I can troubleshoot this issue and restore service to my
> clients?
> Thanx.