Re: Database interactions don't fire from Application_Start in Global.asax?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Please review this article which details the Application lifecycle :

http://msdn2.microsoft.com/en-us/library/ms178473.aspx

Application_Start fires *once* in the application's life.
You cannot use it to capture data about individual users.

Try putting your code in the Session_Start event handler in global.asax.

btw, you'll need to modify your code so that

1. it actually inserts the session id into your database
2. It doesn't use MsgBox ( Msgbox runs client-side, not server-side )




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Christian Blackburn" <christian.Blackburn@xxxxxxxxx> wrote in message
news:1150442804.646872.26720@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Gang,

Let me start by saying I'm using Visual Web Developer 2005 and ASP.net
2.0. Is there something I have to do to get my Global.asax fire when
my application loads. If I set a breakpoint nothing happens also I can
tell that it's not updating my database. I'm storing the users's
session ID in the database to prevent multiple logins. However, when
their session expires it's not clearning their record. Are there
prohibitive constraints on the functionality accessible from
Global.asax?

Thanks a bundle,
Christian Blackburn
-------------------------------------------------------------------------------------------------------------------------------------

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

'Creates the database's Connection object
Dim oConn As New System.Data.Odbc.OdbcConnection("DSN=" &
strDSN)

'Creates a Command object
Dim oCommand As New System.Data.Odbc.OdbcCommand

'Opens the connection
oConn.Open()

'Specifies the command to execute,
'we're clearing all the recorded session IDs
oCommand.CommandText = "UPDATE users " & vbCrLf & _
"SET session_id = '';"

MsgBox(oCommand.CommandText)

'Tells the command object to use the connection above
oCommand.Connection = oConn

'Executes the command
oCommand.ExecuteNonQuery()

'Closes the database connection
oConn.Close()

End Sub

-------------------------------------------------------------------------------------------------------------------------------------



.



Relevant Pages

  • Re: why not SQL Authentication?
    ... you're going to have to go to the database to get your data. ... Now what doesn't make sense is for me is to close the command object, ... Why wouldn't I just cache that command object so ... that I could just reuse it again without having to set a connection object ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Database interactions dont fire from Application_Start in Global.asax?
    ... session ID in the database to prevent multiple logins. ... 'Creates the database's Connection object ... 'Tells the command object to use the connection above ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Servlet and row-level lock
    ... > in which users can select orders from a DB2 database, modify the order, or ... the class mantains a Connection to the database and it's responsible ... > with a select for update, saving on a session the instance, and redirect to ...
    (comp.lang.java.databases)
  • Re: Try...Catch...Finally not firing finally?
    ... We had a trace running on the DB end and it kept saying that the session was never closed, ... Put a trace from the db end to see if the close command is funneling thru to the database engine. ... Anyway, if the connection errors, the Finally closes the connection. ... I debug my web app and step through a function that I am purposly erroring on. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: SQL Server 2005 Express connection error?
    ... //Obtain the database connection string ... //Obtain a database specific connection object ... //Create a database specific command object ...
    (microsoft.public.dotnet.framework.adonet)