navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

Operation is not allowed when the object is closed.

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Operation is not allowed when the object is closed.
Page: [1]
 
bango

 

Posts: 40
Joined: 8/23/2004
Status: offline

 
Operation is not allowed when the object is closed. - 11/12/2004 12:48:42   
Operation is not allowed when the object is closed.

I am having this problem when performing multiple inserts into different DB's on the same page. The data actually inserts however the web page does not refresh properly. The code is included.

<%
'First we create a connection object
Set Conn = Server.CreateObject("ADODB.Connection")

'Next, we open the connection object by calling the connection string
'that FrontPage created and stored in the global.asa file when the "customers" 
'connection was created
Conn.Open Application("customers_ConnectionString")

'Then we create a record set object and a SQL statement
Set RS = Conn.Execute ("SELECT * From tbl_Customers WHERE Username = '" & Session("txtfrom") & "'")

'Loop through the database to check for the users information
Do until RS.EOF
Username = RS("Username")
RS.MoveNext
loop

'Close the recordset and database connection
RS.Close
Set RS = nothing
Conn.Close
Set Conn = nothing

'If the username given is not in the database then we don't do anything.
'Otherwise, we create the session objects
IF Username = "" Then %>
<input type="hidden" name="hidden" value="<% = Request.Form("txtFrom") %>" size="20">
<%
'First we create a connection object
Set Conn = Server.CreateObject("ADODB.Connection")

'Next, we open the connection object by calling the connection string
'that FrontPage created and stored in the global.asa file when the "customers" 
'connection was created
Conn.Open Application("customers_ConnectionString")

'Then we create a record set object and a SQL statement
Set RS = Conn.Execute ("INSERT INTO tbl_customers (Username,CustomerType,Zip,Phone,UserIPAddress) VALUES ('" & Request.Form("txtFrom") & "','4','" & Request.Form("zipCode") & "','" & Request.Form("areaCode") & "-" & Request.Form("prefix") & "-" & Request.Form("lineNumber") & "','" & Request.ServerVariables("REMOTE_ADDR") & "')")

Do until RS.EOF
RS.MoveNext
loop

'Close the recordset and database connection
RS.Close
Set RS = nothing
Conn.Close
Set Conn = nothing
%>
<% Else
End IF
%>

<%
'First we create a connection object
Set Conn = Server.CreateObject("ADODB.Connection")

'Next, we open the connection object by calling the connection string
'that FrontPage created and stored in the global.asa file when the "customers" 
'connection was created
Conn.Open Application("emaildata_ConnectionString")

'Then we create a record set object and a SQL statement
Set RS = Conn.Execute ("INSERT INTO tbl_EmailRecords (Username,EmailZipCode,EmailPhone,ID,TradeIn,Finance,TimeFrame,TradeYear,TradeMake,TradeModel,TradeMileage,EmailType,UserIPAddress) VALUES ('" & Request.Form("txtFrom") & "','" & Request.Form("zipCode") & "','" & Request.Form("areaCode") & "-" & Request.Form("prefix") & "-" & Request.Form("lineNumber") & "','" & Request.Form("ID") & "','" & Request.Form("R1") & "','" & Request.Form("Finance") & "','" & Request.Form("TimeFrame") & "','" & Request.Form("TradeYear") & "','" & Request.Form("TradeMake") & "','" & Request.Form("TradeModel") & "','" & Request.Form("TradeMileage") & "','2','" & Request.ServerVariables("REMOTE_ADDR") & "')")

Do until RS.EOF
RS.MoveNext
loop

'Close the recordset and database connection
RS.Close
Set RS = nothing
Conn.Close
Set Conn = nothing
%>
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Operation is not allowed when the object is closed. - 11/12/2004 13:19:19   
try this :

<%
'First we create a connection object
Set Conn = Server.CreateObject("ADODB.Connection")

'Next, we open the connection object by calling the connection string
'that FrontPage created and stored in the global.asa file when the "customers" 
'connection was created
Conn.Open Application("customers_ConnectionString")

'Then we create a record set object and a SQL statement
Set RS = Conn.Execute ("SELECT Username From tbl_Customers WHERE Username = '" & Session("txtfrom") & "'")

'Loop through the database to check for the users information
Do until RS.EOF
Username = RS(0)
RS.MoveNext
loop

'Close the recordset and database connection
RS.Close
Set RS = nothing

'If the username given is not in the database then we don't do anything.
'Otherwise, we create the session objects
IF Username = "" Then %>
<input type="hidden" name="hidden" value="<% = Request.Form("txtFrom") %>" size="20">
<%

'Then we create a record set object and a SQL statement
Conn.Execute ("INSERT INTO tbl_customers (Username,CustomerType,Zip,Phone,UserIPAddress) VALUES ('" & Request.Form("txtFrom") & "','4','" & Request.Form("zipCode") & "','" & Request.Form("areaCode") & "-" & Request.Form("prefix") & "-" & Request.Form("lineNumber") & "','" & Request.ServerVariables("REMOTE_ADDR") & "')")

End IF

'Then we create a record set object and a SQL statement <-- Should this be above the end if?
Conn.Execute ("INSERT INTO tbl_EmailRecords (Username,EmailZipCode,EmailPhone,ID,TradeIn,Finance,TimeFrame,TradeYear,TradeMake,TradeModel,TradeMileage,EmailType,UserIPAddress) VALUES ('" & Request.Form("txtFrom") & "','" & Request.Form("zipCode") & "','" & Request.Form("areaCode") & "-" & Request.Form("prefix") & "-" & Request.Form("lineNumber") & "','" & Request.Form("ID") & "','" & Request.Form("R1") & "','" & Request.Form("Finance") & "','" & Request.Form("TimeFrame") & "','" & Request.Form("TradeYear") & "','" & Request.Form("TradeMake") & "','" & Request.Form("TradeModel") & "','" & Request.Form("TradeMileage") & "','2','" & Request.ServerVariables("REMOTE_ADDR") & "')")

'Close the database connection

Conn.Close
Set Conn = nothing
%>


Note - you should be checking your database input for injected characters

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bango)
bango

 

Posts: 40
Joined: 8/23/2004
Status: offline

 
RE: Operation is not allowed when the object is closed. - 11/12/2004 13:50:42   
Spooky,

Error: Could not find output table 'tbl_EmailRecords'.

I'm assuming this is due to the fact that this table is located in a DB seperate than the customers connection string (tbl_EmailRecords located in Emaildata connection string) which is stripped out of the new code. Any ideas?

Much Appreciated

(in reply to bango)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Operation is not allowed when the object is closed. - 11/12/2004 14:06:58   
Ahh - sorry, didnt notice that.
Yes, either put it in the same database, or close the previous connection and reopen the new one.

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bango)
bango

 

Posts: 40
Joined: 8/23/2004
Status: offline

 
RE: Operation is not allowed when the object is closed. - 11/12/2004 14:23:41   
Understandable, Your only trying to maintain about 200,000 pages Spooky. Get it together. HA ! Just kidding. Your extremly knowledgable on this and impact alot of individuals. For that I thank you. As for the overall error on this issue. I have resolved it based on your suggestions however I am unclear as to what your changes impacted. Is setting Username = RS(0) the solution and in doing so what does that effectively do ?

Thanks Again
bando

(in reply to bango)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Operation is not allowed when the object is closed. - 11/12/2004 14:30:47   
I think your issue related to doing :
Do until RS.EOF
RS.MoveNext
loop

After an insert.
Its not necessary, and as you arent expecting any results in return, you only need to execute the SQL against the connection and not open a recordset.

With Username, youll notice I changed SELECT * to SELECT Username
As you only required "username", its much more efficient just to return that column (rather than all(*))

Using the ordinal rs(0) is faster, but just another way of getting the first column ( 0 based) from the SQL string.

If your SQL was "SELECT ID, Username FROM....." then you would do this :

ID = rs(0)
Username=rs(1)

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bango)
bango

 

Posts: 40
Joined: 8/23/2004
Status: offline

 
RE: Operation is not allowed when the object is closed. - 11/12/2004 14:50:41   
Wonderful,

Thanks again for the assistance and explanation.

(in reply to Spooky)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Operation is not allowed when the object is closed.
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts