Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Operation is not allowed when the object is closed.

    Edit: God dam it! Just saw the problem, I was closing the connection in the add_to_datebase function! That was hiding for a while... sorry.

    Any ideas here guys? This is what I get onscreen
    Error: Operation is not allowed when the object is closed.:INSERT INTO sales (uid,product,quantity,printed,saleDate,jpgId) VALUES (1,'LR',2,0,#2013/8/1 10:03:52 PM#,722)

    ASP
    Code:
    <!--#include file="functions.asp"-->
    <%
    'Get the users ID and the current date and time
    uid = Request.Cookies("uid")("id")
    datetime = ISODate(Request.Cookies("sdate")&" "&Time)
    
    if (uid = "") then
    	response.write "Error: Please log back in to add sales"
    else
    	'Create connection and load users database
    	set conn=Server.CreateObject("ADODB.Connection")
    	conn.Provider="Microsoft.ACE.OLEDB.12.0"
    	conn.Open Server.MapPath("/nightclub_photography/data/database/jamsnaps.mdb")
    
    	Dim sales, saleId, query
    	Set sales = ParseSales(Request("sale"))
    	
    	'Start displaying results
    	For Each saleId In sales		
    		'Display products
    		For Each saleProd In sales(saleId)
    			query = uid&","                                 'Add user ID
    			query = query & "'" & saleProd & "',"           'Add product
    			query = query & sales(saleId)(saleProd) & ","   'Add product quantity
    			query = query & 0 & ","                         'Has it been printed, not yet
    			query = query & datetime & ","                  'Sale add date and time
    			query = query & saleId                          'Sale JPG ID for printing later
    			
    			handle = add_to_database("sales","uid,product,quantity,printed,saleDate,jpgId",query)
    			
    			if handle <> "" then
    				isError = true
    				msgError = handle
    			end if
    		Next		
    	'Add next sale
    	Next
    	
    	'Any errors?
    	if isError = true then
    		response.write "Error: "&msgError
    	else
    		response.write "Message: Sales successfully added, get ready to print!"
    	end if
    	
    	'Close database connection
    	conn.close
    end if
    %>
    Function
    Code:
    function add_to_database(where,column,values)		
    	'Create query
    	sql = "INSERT INTO " & where & " (" & column & ") VALUES (" & values & ")"
    	on error resume next
    	'Add images to database
    	conn.Execute sql,recaffected
    	
    	if err<>0 then
    		add_to_database = err.description &":"&sql&"<br />"
    	end if
    	
    	'Destroy connection
    	sql = ""
    	conn.close
    end function
    Last edited by martynball; 08-01-2013 at 11:10 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •