ASP Session again
-
Hello, I've got the following code test.asp <%@ language="Javascript" %> <% var Connection,Recordset; Connection = Server.CreateObject("ADODB.Connection"); Connection.Open("thesourcename"); var strSQLQuery = "SELECT * FROM clients WHERE .... " Recordset = Connection.Execute(strSQLQuery); Session("test") = Recordset.Fields("user_name"); Response.Redirect("test1.asp"); %> and I've got another code ... test1.asp <%@ language="Javascript" %> <% Response.Write(Session("test")); %> Someone PLEASE tell me what am I doing WROOOOOOOOONG bacause ASP is driving me crazy. The book sais that the Session object should store the values from page to page. I get an ADODB.Field no longer available error message. Could someone please tell me why ????????????????? I've got almost the same code in VBScript and it works .... WHAT'S WRONG ?? Thank you !
-
Hello, I've got the following code test.asp <%@ language="Javascript" %> <% var Connection,Recordset; Connection = Server.CreateObject("ADODB.Connection"); Connection.Open("thesourcename"); var strSQLQuery = "SELECT * FROM clients WHERE .... " Recordset = Connection.Execute(strSQLQuery); Session("test") = Recordset.Fields("user_name"); Response.Redirect("test1.asp"); %> and I've got another code ... test1.asp <%@ language="Javascript" %> <% Response.Write(Session("test")); %> Someone PLEASE tell me what am I doing WROOOOOOOOONG bacause ASP is driving me crazy. The book sais that the Session object should store the values from page to page. I get an ADODB.Field no longer available error message. Could someone please tell me why ????????????????? I've got almost the same code in VBScript and it works .... WHAT'S WRONG ?? Thank you !
Apologies for not answering your actual question but don't do what you are doing. You are leaving connection objects to the database open, redirecting to other pages without closing them. That is not good. Maybe explain what you want to do and we can recommend some better ways of doing it. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?
-
Apologies for not answering your actual question but don't do what you are doing. You are leaving connection objects to the database open, redirecting to other pages without closing them. That is not good. Maybe explain what you want to do and we can recommend some better ways of doing it. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?
Don't mind the fact that I'm not closing the recordset and the connection. In real life I do that ... :) The problem is that I want the test1.asp script to display the content of the Session("UserName") but I am not succesful because I get an error saying that : Error Type: ADODB.Field (0x80020009) Object is no longer valid. /meteo/test1.asp, line 3 Here is the code: test.asp <%@ language="Javascript" %> <% var Connection,Recordset; Connection = Server.CreateObject("ADODB.Connection"); Recordset = Server.CreateObject("ADODB.Recordset"); Connection.Open("Clienti"); var strSQLQuery = "SELECT * FROM clienti WHERE nume_utilizator = \'" + "radio" +"\'"; Recordset=Connection.Execute(strSQLQuery); Session("UserName") = Recordset.Fields("nume_utilizator"); Recordset.Close(); Connection.Close(); Response.Redirect("test1.asp"); %> and test1.asp <%@ language="Javascript" %> <% Response.Write(Session("UserName")); %>
-
Don't mind the fact that I'm not closing the recordset and the connection. In real life I do that ... :) The problem is that I want the test1.asp script to display the content of the Session("UserName") but I am not succesful because I get an error saying that : Error Type: ADODB.Field (0x80020009) Object is no longer valid. /meteo/test1.asp, line 3 Here is the code: test.asp <%@ language="Javascript" %> <% var Connection,Recordset; Connection = Server.CreateObject("ADODB.Connection"); Recordset = Server.CreateObject("ADODB.Recordset"); Connection.Open("Clienti"); var strSQLQuery = "SELECT * FROM clienti WHERE nume_utilizator = \'" + "radio" +"\'"; Recordset=Connection.Execute(strSQLQuery); Session("UserName") = Recordset.Fields("nume_utilizator"); Recordset.Close(); Connection.Close(); Response.Redirect("test1.asp"); %> and test1.asp <%@ language="Javascript" %> <% Response.Write(Session("UserName")); %>
Ok, my ASP is a bit rusty but I think the problem is because you are storing the object itself, not the value. Because you close the connection, the object becomes invalid. Damn, JScript needs a ToString() method :-D David Wulff, a JScript genius, says you should use
Session("UserName") = String(Recordset.Fields("nume_utilizator"));
. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand? -
Ok, my ASP is a bit rusty but I think the problem is because you are storing the object itself, not the value. Because you close the connection, the object becomes invalid. Damn, JScript needs a ToString() method :-D David Wulff, a JScript genius, says you should use
Session("UserName") = String(Recordset.Fields("nume_utilizator"));
. regards, Paul Watson Bluegrass South Africa Brian Welsch wrote: "blah blah blah, maybe a potato?" while translating my Afrikaans. Crikey! ain't life grand?Seems to be working (for now) ... thank you !
-
Hello, I've got the following code test.asp <%@ language="Javascript" %> <% var Connection,Recordset; Connection = Server.CreateObject("ADODB.Connection"); Connection.Open("thesourcename"); var strSQLQuery = "SELECT * FROM clients WHERE .... " Recordset = Connection.Execute(strSQLQuery); Session("test") = Recordset.Fields("user_name"); Response.Redirect("test1.asp"); %> and I've got another code ... test1.asp <%@ language="Javascript" %> <% Response.Write(Session("test")); %> Someone PLEASE tell me what am I doing WROOOOOOOOONG bacause ASP is driving me crazy. The book sais that the Session object should store the values from page to page. I get an ADODB.Field no longer available error message. Could someone please tell me why ????????????????? I've got almost the same code in VBScript and it works .... WHAT'S WRONG ?? Thank you !
Use the below <% @LANGUAGE = VBScript%> This will also help you to get rid from unimportant error. And be COOL. Himadrish Laha