Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: connection problems


Message #1 by "John Tyson" <jtyson@t...> on Tue, 28 May 2002 14:15:26 -0700
I have a page load procedure where
1. if user is valid call stored procedure
2. within that if statement, if not page.ispostback call another stored
procedure.

I am getting the following error: An error has occurred:
System.InvalidOperationException: The connection is already Open
(state=3DOpen). at System.Data.SqlClient.SqlConnection.Open() at
ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)

I partially understand what is going on, but I can find where to fix it.
To my knowledge I leave the connection object open and available for the
second stored procedure when calling the first.  Somewhere it thinks I
not only left it open but I am trying to open it again.  I tried remming
out the dbconn.Open() in the second stored procedure, but then I get
another error:

An error has occurred: System.Data.SqlClient.SqlException: Procedure
sp_CompanyList has no parameters and arguments were supplied. at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
System.Data.SqlClient.SqlCommand.ExecuteReader() at
ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)

I have included my code below.  If someone could take a quick glance at
it I'd really, really appreciate it.



   Sub Page_Load(s As Object, e As EventArgs)

      If User.Identity.IsAuthenticated Then
         displayCredentials.InnerHtml =3D "Current User: " &
User.Identity.Name

            Dim dbconn As SqlConnection =3D New SqlConnection _
               (ConfigurationSettings.AppSettings("ConnectionString"))

            Dim cmd As SqlCommand =3D New SqlCommand("sp_ReqsEntered",
dbconn)
               cmd.CommandType =3D CommandType.StoredProcedure

            Dim reqByParam As SqlParameter =3D
cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
            reqByParam.Direction =3D ParameterDirection.Input
            reqByParam.Value =3D CStr(User.Identity.Name)

            Dim dr As SqlDataReader

            Try
               dbconn.Open()
               dr =3D cmd.ExecuteReader
               'dr =3D 
cmd.ExecuteReader(CommandBehavior.CloseConnection)

               lstTodaysReqs.DataSource =3D dr
               lstTodaysReqs.DataBind()

            Catch exc As Exception
               Response.Write("An error has occurred: " &
exc.ToString())

            Finally
               If Not dr is Nothing Then
                  dr.Close()
               End If

            End Try

         If Not Page.IsPostBack Then

            'Dim dbconn As SqlConnection =3D New SqlConnection _
               '(ConfigurationSettings.AppSettings("ConnectionString"))

            'Dim cmd As SqlCommand =3D New SqlCommand()
            With cmd
               .Connection =3D dbconn
               .CommandText =3D "sp_CompanyList"
               .CommandType =3D CommandType.StoredProcedure
            End With

            'Dim dr As SqlDataReader

            Try
               dbconn.Open()
               dr =3D cmd.ExecuteReader()
               'dr =3D 
cmd.ExecuteReader(CommandBehavior.CloseConnection)

               lstCompany.DataSource =3D dr
               lstCompany.DataBind()

            Catch exc As Exception
               Response.Write("An error has occurred: " &
exc.ToString())

            Finally
               If Not dr is Nothing Then
                  dr.Close()
               End If

               lstCompany.Items.Insert(0, "not selected")
                  lstCompany.SelectedIndex =3D 0
                  lstCompany.SelectedItem.Value =3D 0
                  lstCompany.SelectedItem.Text =3D "not selected"

            End Try

         End If

      Else
         displayCredentials.InnerHtml =3D "You must be an authenticated
user prior to using this service."
      End If

   End Sub







Message #2 by Imar Spaanjaars <Imar@S...> on Tue, 28 May 2002 23:22:05 +0200
It not only thinks you are trying to open it again, it knows THAT you are 
opening it again ;-)


Take a look at this:

' First sproc
>             Try
>                dbconn.Open()
>                dr = cmd.ExecuteReader


' Second sproc
>             Try
>                dbconn.Open()
>                dr = cmd.ExecuteReader()


Hmmm, too much caffeine?? ;-)



Imar


At 02:15 PM 5/28/2002 -0700, you wrote:
>I have a page load procedure where
>1. if user is valid call stored procedure
>2. within that if statement, if not page.ispostback call another stored
>procedure.
>
>I am getting the following error: An error has occurred:
>System.InvalidOperationException: The connection is already Open
>(state=Open). at System.Data.SqlClient.SqlConnection.Open() at
>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>
>I partially understand what is going on, but I can find where to fix it.
>To my knowledge I leave the connection object open and available for the
>second stored procedure when calling the first.  Somewhere it thinks I
>not only left it open but I am trying to open it again.  I tried remming
>out the dbconn.Open() in the second stored procedure, but then I get
>another error:
>
>An error has occurred: System.Data.SqlClient.SqlException: Procedure
>sp_CompanyList has no parameters and arguments were supplied. at
>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
>System.Data.SqlClient.SqlCommand.ExecuteReader() at
>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>
>I have included my code below.  If someone could take a quick glance at
>it I'd really, really appreciate it.
>
>
>
>    Sub Page_Load(s As Object, e As EventArgs)
>
>       If User.Identity.IsAuthenticated Then
>          displayCredentials.InnerHtml = "Current User: " &
>User.Identity.Name
>
>             Dim dbconn As SqlConnection = New SqlConnection _
>                (ConfigurationSettings.AppSettings("ConnectionString"))
>
>             Dim cmd As SqlCommand = New SqlCommand("sp_ReqsEntered",
>dbconn)
>                cmd.CommandType = CommandType.StoredProcedure
>
>             Dim reqByParam As SqlParameter 
>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
>             reqByParam.Direction = ParameterDirection.Input
>             reqByParam.Value = CStr(User.Identity.Name)
>
>             Dim dr As SqlDataReader
>
>             Try
>                dbconn.Open()
>                dr = cmd.ExecuteReader
>                'dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
>
>                lstTodaysReqs.DataSource = dr
>                lstTodaysReqs.DataBind()
>
>             Catch exc As Exception
>                Response.Write("An error has occurred: " &
>exc.ToString())
>
>             Finally
>                If Not dr is Nothing Then
>                   dr.Close()
>                End If
>
>             End Try
>
>          If Not Page.IsPostBack Then
>
>             'Dim dbconn As SqlConnection = New SqlConnection _
>                '(ConfigurationSettings.AppSettings("ConnectionString"))
>
>             'Dim cmd As SqlCommand = New SqlCommand()
>             With cmd
>                .Connection = dbconn
>                .CommandText = "sp_CompanyList"
>                .CommandType = CommandType.StoredProcedure
>             End With
>
>             'Dim dr As SqlDataReader
>
>             Try
>                dbconn.Open()
>                dr = cmd.ExecuteReader()
>                'dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
>
>                lstCompany.DataSource = dr
>                lstCompany.DataBind()
>
>             Catch exc As Exception
>                Response.Write("An error has occurred: " &
>exc.ToString())
>
>             Finally
>                If Not dr is Nothing Then
>                   dr.Close()
>                End If
>
>                lstCompany.Items.Insert(0, "not selected")
>                   lstCompany.SelectedIndex = 0
>                   lstCompany.SelectedItem.Value = 0
>                   lstCompany.SelectedItem.Text = "not selected"
>
>             End Try
>
>          End If
>
>       Else
>          displayCredentials.InnerHtml = "You must be an authenticated
>user prior to using this service."
>       End If
>
>    End Sub
>
>
>
>
>
>
>
>


Message #3 by "John Tyson" <jtyson@t...> on Tue, 28 May 2002 14:32:55 -0700
Hi Imar,

Heh...well, I've been working on this for a while and feel kind of rummy
now.

As I said, I tried remming out the second dbconn.Open(), but that
generated another error:

An error has occurred: System.Data.SqlClient.SqlException: Procedure
>sp_CompanyList has no parameters and arguments were supplied. at
>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
>System.Data.SqlClient.SqlCommand.ExecuteReader() at
>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)

I don't know what this means?  I am not supplying any parameters to the
second sproc, but that seems to be what it is saying...

Any suggestions?


-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Tuesday, May 28, 2002 2:22 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: connection problems

It not only thinks you are trying to open it again, it knows THAT you
are
opening it again ;-)


Take a look at this:

' First sproc
>             Try
>                dbconn.Open()
>                dr =3D cmd.ExecuteReader


' Second sproc
>             Try
>                dbconn.Open()
>                dr =3D cmd.ExecuteReader()


Hmmm, too much caffeine?? ;-)



Imar


At 02:15 PM 5/28/2002 -0700, you wrote:
>I have a page load procedure where
>1. if user is valid call stored procedure
>2. within that if statement, if not page.ispostback call another stored
>procedure.
>
>I am getting the following error: An error has occurred:
>System.InvalidOperationException: The connection is already Open
>(state=3DOpen). at System.Data.SqlClient.SqlConnection.Open() at
>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>
>I partially understand what is going on, but I can find where to fix
it.
>To my knowledge I leave the connection object open and available for
the
>second stored procedure when calling the first.  Somewhere it thinks I
>not only left it open but I am trying to open it again.  I tried
remming
>out the dbconn.Open() in the second stored procedure, but then I get
>another error:
>
>An error has occurred: System.Data.SqlClient.SqlException: Procedure
>sp_CompanyList has no parameters and arguments were supplied. at
>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
>System.Data.SqlClient.SqlCommand.ExecuteReader() at
>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>
>I have included my code below.  If someone could take a quick glance at
>it I'd really, really appreciate it.
>
>
>
>    Sub Page_Load(s As Object, e As EventArgs)
>
>       If User.Identity.IsAuthenticated Then
>          displayCredentials.InnerHtml =3D "Current User: " &
>User.Identity.Name
>
>             Dim dbconn As SqlConnection =3D New SqlConnection _
>                (ConfigurationSettings.AppSettings("ConnectionString"))
>
>             Dim cmd As SqlCommand =3D New SqlCommand("sp_ReqsEntered",
>dbconn)
>                cmd.CommandType =3D CommandType.StoredProcedure
>
>             Dim reqByParam As SqlParameter =3D
>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
>             reqByParam.Direction =3D ParameterDirection.Input
>             reqByParam.Value =3D CStr(User.Identity.Name)
>
>             Dim dr As SqlDataReader
>
>             Try
>                dbconn.Open()
>                dr =3D cmd.ExecuteReader
>                'dr =3D
cmd.ExecuteReader(CommandBehavior.CloseConnection)
>
>                lstTodaysReqs.DataSource =3D dr
>                lstTodaysReqs.DataBind()
>
>             Catch exc As Exception
>                Response.Write("An error has occurred: " &
>exc.ToString())
>
>             Finally
>                If Not dr is Nothing Then
>                   dr.Close()
>                End If
>
>             End Try
>
>          If Not Page.IsPostBack Then
>
>             'Dim dbconn As SqlConnection =3D New SqlConnection _
>
'(ConfigurationSettings.AppSettings("ConnectionString"))
>
>             'Dim cmd As SqlCommand =3D New SqlCommand()
>             With cmd
>                .Connection =3D dbconn
>                .CommandText =3D "sp_CompanyList"
>                .CommandType =3D CommandType.StoredProcedure
>             End With
>
>             'Dim dr As SqlDataReader
>
>             Try
>                dbconn.Open()
>                dr =3D cmd.ExecuteReader()
>                'dr =3D
cmd.ExecuteReader(CommandBehavior.CloseConnection)
>
>                lstCompany.DataSource =3D dr
>                lstCompany.DataBind()
>
>             Catch exc As Exception
>                Response.Write("An error has occurred: " &
>exc.ToString())
>
>             Finally
>                If Not dr is Nothing Then
>                   dr.Close()
>                End If
>
>                lstCompany.Items.Insert(0, "not selected")
>                   lstCompany.SelectedIndex =3D 0
>                   lstCompany.SelectedItem.Value =3D 0
>                   lstCompany.SelectedItem.Text =3D "not selected"
>
>             End Try
>
>          End If
>
>       Else
>          displayCredentials.InnerHtml =3D "You must be an 
authenticated
>user prior to using this service."
>       End If
>
>    End Sub
>
>
>
>
>
>
>
>



Message #4 by Imar Spaanjaars <Imar@S...> on Tue, 28 May 2002 23:34:37 +0200
Whoops, just realized that -I- didn't read good enough :-( Sorry.

The cmd object still has the parameter assigned from the first command 
object. You should either remove these (look at Command.Parameters.Remove() 
and Command.Parameters.RemoveAt()), or easier yet, just create a second 
command object. I think when you reuse the connection, the overhead of 
creating a second command object is rather minimal.

HtH


Imar


At 11:22 PM 5/28/2002 +0200, you wrote:
>It not only thinks you are trying to open it again, it knows THAT you are 
>opening it again ;-)
>
>
>Take a look at this:
>
>' First sproc
>>             Try
>>                dbconn.Open()
>>                dr = cmd.ExecuteReader
>
>
>' Second sproc
>>             Try
>>                dbconn.Open()
>>                dr = cmd.ExecuteReader()
>
>
>Hmmm, too much caffeine?? ;-)
>
>
>
>Imar
>
>
>At 02:15 PM 5/28/2002 -0700, you wrote:
>>I have a page load procedure where
>>1. if user is valid call stored procedure
>>2. within that if statement, if not page.ispostback call another stored
>>procedure.
>>
>>I am getting the following error: An error has occurred:
>>System.InvalidOperationException: The connection is already Open
>>(state=Open). at System.Data.SqlClient.SqlConnection.Open() at
>>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>>
>>I partially understand what is going on, but I can find where to fix it.
>>To my knowledge I leave the connection object open and available for the
>>second stored procedure when calling the first.  Somewhere it thinks I
>>not only left it open but I am trying to open it again.  I tried remming
>>out the dbconn.Open() in the second stored procedure, but then I get
>>another error:
>>
>>An error has occurred: System.Data.SqlClient.SqlException: Procedure
>>sp_CompanyList has no parameters and arguments were supplied. at
>>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
>>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
>>System.Data.SqlClient.SqlCommand.ExecuteReader() at
>>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>>
>>I have included my code below.  If someone could take a quick glance at
>>it I'd really, really appreciate it.
>>
>>
>>
>>    Sub Page_Load(s As Object, e As EventArgs)
>>
>>       If User.Identity.IsAuthenticated Then
>>          displayCredentials.InnerHtml = "Current User: " &
>>User.Identity.Name
>>
>>             Dim dbconn As SqlConnection = New SqlConnection _
>>                (ConfigurationSettings.AppSettings("ConnectionString"))
>>
>>             Dim cmd As SqlCommand = New SqlCommand("sp_ReqsEntered",
>>dbconn)
>>                cmd.CommandType = CommandType.StoredProcedure
>>
>>             Dim reqByParam As SqlParameter 
>>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
>>             reqByParam.Direction = ParameterDirection.Input
>>             reqByParam.Value = CStr(User.Identity.Name)
>>
>>             Dim dr As SqlDataReader
>>
>>             Try
>>                dbconn.Open()
>>                dr = cmd.ExecuteReader
>>                'dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
>>
>>                lstTodaysReqs.DataSource = dr
>>                lstTodaysReqs.DataBind()
>>
>>             Catch exc As Exception
>>                Response.Write("An error has occurred: " &
>>exc.ToString())
>>
>>             Finally
>>                If Not dr is Nothing Then
>>                   dr.Close()
>>                End If
>>
>>             End Try
>>
>>          If Not Page.IsPostBack Then
>>
>>             'Dim dbconn As SqlConnection = New SqlConnection _
>>                '(ConfigurationSettings.AppSettings("ConnectionString"))
>>
>>             'Dim cmd As SqlCommand = New SqlCommand()
>>             With cmd
>>                .Connection = dbconn
>>                .CommandText = "sp_CompanyList"
>>                .CommandType = CommandType.StoredProcedure
>>             End With
>>
>>             'Dim dr As SqlDataReader
>>
>>             Try
>>                dbconn.Open()
>>                dr = cmd.ExecuteReader()
>>                'dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
>>
>>                lstCompany.DataSource = dr
>>                lstCompany.DataBind()
>>
>>             Catch exc As Exception
>>                Response.Write("An error has occurred: " &
>>exc.ToString())
>>
>>             Finally
>>                If Not dr is Nothing Then
>>                   dr.Close()
>>                End If
>>
>>                lstCompany.Items.Insert(0, "not selected")
>>                   lstCompany.SelectedIndex = 0
>>                   lstCompany.SelectedItem.Value = 0
>>                   lstCompany.SelectedItem.Text = "not selected"
>>
>>             End Try
>>
>>          End If
>>
>>       Else
>>          displayCredentials.InnerHtml = "You must be an authenticated
>>user prior to using this service."
>>       End If
>>
>>    End Sub
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>---
>Change your mail options at http://p2p.wrox.com/manager.asp or to 
>unsubscribe send a blank email to 


Message #5 by "John Tyson" <jtyson@t...> on Tue, 28 May 2002 14:53:02 -0700
Hi Imar,

Thanks - I used .Parameters.Remove(ReqByParam) and it works now.

Since you have read through my code I was wondering if you might be able
to offer some more advice:

The first stored procedure builds a list of submitted requests by the
logged in user.  My intent is for the list to grow as the user submits
requests, so they can see what they have submitted so far.

I loaded this sproc on page load thinking it would refresh the list on
page load and postback.  However, this doesn't work quite right.  Say I
save one record.  Nothing happens.  I save a second and the first record
appears in the list.  It lags one record behind - the only way to make
the last record show right after clicking the submit button is to click
refresh on the browser.

I tried stating autopostback =3D true for the submit button.  Didn't 
work.
Do I need to also specify response.redirect to the same page on button
click to make my code work?  Can you help me?

Thanks,

John

-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Tuesday, May 28, 2002 2:35 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: connection problems

Whoops, just realized that -I- didn't read good enough :-( Sorry.

The cmd object still has the parameter assigned from the first command
object. You should either remove these (look at
Command.Parameters.Remove()
and Command.Parameters.RemoveAt()), or easier yet, just create a second
command object. I think when you reuse the connection, the overhead of
creating a second command object is rather minimal.

HtH


Imar


At 11:22 PM 5/28/2002 +0200, you wrote:
>It not only thinks you are trying to open it again, it knows THAT you
are
>opening it again ;-)
>
>
>Take a look at this:
>
>' First sproc
>>             Try
>>                dbconn.Open()
>>                dr =3D cmd.ExecuteReader
>
>
>' Second sproc
>>             Try
>>                dbconn.Open()
>>                dr =3D cmd.ExecuteReader()
>
>
>Hmmm, too much caffeine?? ;-)
>
>
>
>Imar
>
>
>At 02:15 PM 5/28/2002 -0700, you wrote:
>>I have a page load procedure where
>>1. if user is valid call stored procedure
>>2. within that if statement, if not page.ispostback call another
stored
>>procedure.
>>
>>I am getting the following error: An error has occurred:
>>System.InvalidOperationException: The connection is already Open
>>(state=3DOpen). at System.Data.SqlClient.SqlConnection.Open() at
>>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>>
>>I partially understand what is going on, but I can find where to fix
it.
>>To my knowledge I leave the connection object open and available for
the
>>second stored procedure when calling the first.  Somewhere it thinks I
>>not only left it open but I am trying to open it again.  I tried
remming
>>out the dbconn.Open() in the second stored procedure, but then I get
>>another error:
>>
>>An error has occurred: System.Data.SqlClient.SqlException: Procedure
>>sp_CompanyList has no parameters and arguments were supplied. at
>>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
>>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
>>System.Data.SqlClient.SqlCommand.ExecuteReader() at
>>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
>>
>>I have included my code below.  If someone could take a quick glance
at
>>it I'd really, really appreciate it.
>>
>>
>>
>>    Sub Page_Load(s As Object, e As EventArgs)
>>
>>       If User.Identity.IsAuthenticated Then
>>          displayCredentials.InnerHtml =3D "Current User: " &
>>User.Identity.Name
>>
>>             Dim dbconn As SqlConnection =3D New SqlConnection _
>>
(ConfigurationSettings.AppSettings("ConnectionString"))
>>
>>             Dim cmd As SqlCommand =3D New 
SqlCommand("sp_ReqsEntered",
>>dbconn)
>>                cmd.CommandType =3D CommandType.StoredProcedure
>>
>>             Dim reqByParam As SqlParameter =3D
>>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
>>             reqByParam.Direction =3D ParameterDirection.Input
>>             reqByParam.Value =3D CStr(User.Identity.Name)
>>
>>             Dim dr As SqlDataReader
>>
>>             Try
>>                dbconn.Open()
>>                dr =3D cmd.ExecuteReader
>>                'dr =3D
cmd.ExecuteReader(CommandBehavior.CloseConnection)
>>
>>                lstTodaysReqs.DataSource =3D dr
>>                lstTodaysReqs.DataBind()
>>
>>             Catch exc As Exception
>>                Response.Write("An error has occurred: " &
>>exc.ToString())
>>
>>             Finally
>>                If Not dr is Nothing Then
>>                   dr.Close()
>>                End If
>>
>>             End Try
>>
>>          If Not Page.IsPostBack Then
>>
>>             'Dim dbconn As SqlConnection =3D New SqlConnection _
>>
'(ConfigurationSettings.AppSettings("ConnectionString"))
>>
>>             'Dim cmd As SqlCommand =3D New SqlCommand()
>>             With cmd
>>                .Connection =3D dbconn
>>                .CommandText =3D "sp_CompanyList"
>>                .CommandType =3D CommandType.StoredProcedure
>>             End With
>>
>>             'Dim dr As SqlDataReader
>>
>>             Try
>>                dbconn.Open()
>>                dr =3D cmd.ExecuteReader()
>>                'dr =3D
cmd.ExecuteReader(CommandBehavior.CloseConnection)
>>
>>                lstCompany.DataSource =3D dr
>>                lstCompany.DataBind()
>>
>>             Catch exc As Exception
>>                Response.Write("An error has occurred: " &
>>exc.ToString())
>>
>>             Finally
>>                If Not dr is Nothing Then
>>                   dr.Close()
>>                End If
>>
>>                lstCompany.Items.Insert(0, "not selected")
>>                   lstCompany.SelectedIndex =3D 0
>>                   lstCompany.SelectedItem.Value =3D 0
>>                   lstCompany.SelectedItem.Text =3D "not selected"
>>
>>             End Try
>>
>>          End If
>>
>>       Else
>>          displayCredentials.InnerHtml =3D "You must be an 
authenticated
>>user prior to using this service."
>>       End If
>>
>>    End Sub
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>---
>Change your mail options at http://p2p.wrox.com/manager.asp or to
>unsubscribe send a blank email to 



Message #6 by Imar Spaanjaars <Imar@S...> on Wed, 29 May 2002 18:36:05 +0200
Hi Chris,

Sorry for the late reaction. I had quite a busy day today.

Do you use IsPostBack in your code? Did you enable caching of any kind?
Usually, you should be able to retrieve the new records, as the query 
should execute every time you request the page.

If this doesn't work, post the relevant parts of the page (including 
pageheader directives and code behind) so we can take a look at it.

Imar


At 02:53 PM 5/28/2002 -0700, you wrote:
>Hi Imar,
>
>Thanks - I used .Parameters.Remove(ReqByParam) and it works now.
>
>Since you have read through my code I was wondering if you might be able
>to offer some more advice:
>
>The first stored procedure builds a list of submitted requests by the
>logged in user.  My intent is for the list to grow as the user submits
>requests, so they can see what they have submitted so far.
>
>I loaded this sproc on page load thinking it would refresh the list on
>page load and postback.  However, this doesn't work quite right.  Say I
>save one record.  Nothing happens.  I save a second and the first record
>appears in the list.  It lags one record behind - the only way to make
>the last record show right after clicking the submit button is to click
>refresh on the browser.
>
>I tried stating autopostback = true for the submit button.  Didn't work.
>Do I need to also specify response.redirect to the same page on button
>click to make my code work?  Can you help me?
>
>Thanks,
>
>John
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, May 28, 2002 2:35 PM
>To: aspx_beginners
>Subject: [aspx_beginners] Re: connection problems
>
>Whoops, just realized that -I- didn't read good enough :-( Sorry.
>
>The cmd object still has the parameter assigned from the first command
>object. You should either remove these (look at
>Command.Parameters.Remove()
>and Command.Parameters.RemoveAt()), or easier yet, just create a second
>command object. I think when you reuse the connection, the overhead of
>creating a second command object is rather minimal.
>
>HtH
>
>
>Imar
>
>
>At 11:22 PM 5/28/2002 +0200, you wrote:
> >It not only thinks you are trying to open it again, it knows THAT you
>are
> >opening it again ;-)
> >
> >
> >Take a look at this:
> >
> >' First sproc
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader
> >
> >
> >' Second sproc
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader()
> >
> >
> >Hmmm, too much caffeine?? ;-)
> >
> >
> >
> >Imar
> >
> >
> >At 02:15 PM 5/28/2002 -0700, you wrote:
> >>I have a page load procedure where
> >>1. if user is valid call stored procedure
> >>2. within that if statement, if not page.ispostback call another
>stored
> >>procedure.
> >>
> >>I am getting the following error: An error has occurred:
> >>System.InvalidOperationException: The connection is already Open
> >>(state=Open). at System.Data.SqlClient.SqlConnection.Open() at
> >>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
> >>
> >>I partially understand what is going on, but I can find where to fix
>it.
> >>To my knowledge I leave the connection object open and available for
>the
> >>second stored procedure when calling the first.  Somewhere it thinks I
> >>not only left it open but I am trying to open it again.  I tried
>remming
> >>out the dbconn.Open() in the second stored procedure, but then I get
> >>another error:
> >>
> >>An error has occurred: System.Data.SqlClient.SqlException: Procedure
> >>sp_CompanyList has no parameters and arguments were supplied. at
> >>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> >>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
> >>System.Data.SqlClient.SqlCommand.ExecuteReader() at
> >>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
> >>
> >>I have included my code below.  If someone could take a quick glance
>at
> >>it I'd really, really appreciate it.
> >>
> >>
> >>
> >>    Sub Page_Load(s As Object, e As EventArgs)
> >>
> >>       If User.Identity.IsAuthenticated Then
> >>          displayCredentials.InnerHtml = "Current User: " &
> >>User.Identity.Name
> >>
> >>             Dim dbconn As SqlConnection = New SqlConnection _
> >>
>(ConfigurationSettings.AppSettings("ConnectionString"))
> >>
> >>             Dim cmd As SqlCommand = New SqlCommand("sp_ReqsEntered",
> >>dbconn)
> >>                cmd.CommandType = CommandType.StoredProcedure
> >>
> >>             Dim reqByParam As SqlParameter 
> >>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
> >>             reqByParam.Direction = ParameterDirection.Input
> >>             reqByParam.Value = CStr(User.Identity.Name)
> >>
> >>             Dim dr As SqlDataReader
> >>
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader
> >>                'dr 
>cmd.ExecuteReader(CommandBehavior.CloseConnection)
> >>
> >>                lstTodaysReqs.DataSource = dr
> >>                lstTodaysReqs.DataBind()
> >>
> >>             Catch exc As Exception
> >>                Response.Write("An error has occurred: " &
> >>exc.ToString())
> >>
> >>             Finally
> >>                If Not dr is Nothing Then
> >>                   dr.Close()
> >>                End If
> >>
> >>             End Try
> >>
> >>          If Not Page.IsPostBack Then
> >>
> >>             'Dim dbconn As SqlConnection = New SqlConnection _
> >>
>'(ConfigurationSettings.AppSettings("ConnectionString"))
> >>
> >>             'Dim cmd As SqlCommand = New SqlCommand()
> >>             With cmd
> >>                .Connection = dbconn
> >>                .CommandText = "sp_CompanyList"
> >>                .CommandType = CommandType.StoredProcedure
> >>             End With
> >>
> >>             'Dim dr As SqlDataReader
> >>
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader()
> >>                'dr 
>cmd.ExecuteReader(CommandBehavior.CloseConnection)
> >>
> >>                lstCompany.DataSource = dr
> >>                lstCompany.DataBind()
> >>
> >>             Catch exc As Exception
> >>                Response.Write("An error has occurred: " &
> >>exc.ToString())
> >>
> >>             Finally
> >>                If Not dr is Nothing Then
> >>                   dr.Close()
> >>                End If
> >>
> >>                lstCompany.Items.Insert(0, "not selected")
> >>                   lstCompany.SelectedIndex = 0
> >>                   lstCompany.SelectedItem.Value = 0
> >>                   lstCompany.SelectedItem.Text = "not selected"
> >>
> >>             End Try
> >>
> >>          End If
> >>
> >>       Else
> >>          displayCredentials.InnerHtml = "You must be an authenticated
> >>user prior to using this service."
> >>       End If
> >>
> >>    End Sub
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >---
> >Change your mail options at http://p2p.wrox.com/manager.asp or to
> >unsubscribe send a blank email to 
>
>
>
>


Message #7 by "John Tyson" <jtyson@t...> on Wed, 29 May 2002 09:48:59 -0700
Hi Imar,

Thanks for responding.  I'm John though ;-)  I have a brother named
Chris...but probably not the Chris whose posts you have been responding
to.

I only use IsPostBack to load dropdownlist values on page load (If Not
Page.IsPostBack Then...) - so no.  Don't use AutoPostBack =3D "true" in
this page either, and am not working with caching at all.

I had assigned the procedure to call the requests list to the submit
button OnClick event, but that's where I ran into the problem that the
list would only update every two button clicks, and when it did refresh
it would show the record entered two clicks ago but not the most current
submission.

I moved the procedure to page_load, but in order to make it refresh I
had to add a response.redirect back to the same page.  I don't think
this is the correct approach because I don't want to hit the server each
time - but does this actually create more work for the server if a new
record is being submitted to the database anyway?

If you want I can change my code back to the way I had it originally and
post it for you to look at.

Thanks,

John

-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Wednesday, May 29, 2002 9:36 AM
To: aspx_beginners
Subject: [aspx_beginners] Re: connection problems

Hi Chris,

Sorry for the late reaction. I had quite a busy day today.

Do you use IsPostBack in your code? Did you enable caching of any kind?
Usually, you should be able to retrieve the new records, as the query
should execute every time you request the page.

If this doesn't work, post the relevant parts of the page (including
pageheader directives and code behind) so we can take a look at it.

Imar


At 02:53 PM 5/28/2002 -0700, you wrote:
>Hi Imar,
>
>Thanks - I used .Parameters.Remove(ReqByParam) and it works now.
>
>Since you have read through my code I was wondering if you might be
able
>to offer some more advice:
>
>The first stored procedure builds a list of submitted requests by the
>logged in user.  My intent is for the list to grow as the user submits
>requests, so they can see what they have submitted so far.
>
>I loaded this sproc on page load thinking it would refresh the list on
>page load and postback.  However, this doesn't work quite right.  Say I
>save one record.  Nothing happens.  I save a second and the first
record
>appears in the list.  It lags one record behind - the only way to make
>the last record show right after clicking the submit button is to click
>refresh on the browser.
>
>I tried stating autopostback =3D true for the submit button.  Didn't
work.
>Do I need to also specify response.redirect to the same page on button
>click to make my code work?  Can you help me?
>
>Thanks,
>
>John
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, May 28, 2002 2:35 PM
>To: aspx_beginners
>Subject: [aspx_beginners] Re: connection problems
>
>Whoops, just realized that -I- didn't read good enough :-( Sorry.
>
>The cmd object still has the parameter assigned from the first command
>object. You should either remove these (look at
>Command.Parameters.Remove()
>and Command.Parameters.RemoveAt()), or easier yet, just create a second
>command object. I think when you reuse the connection, the overhead of
>creating a second command object is rather minimal.
>
>HtH
>
>
>Imar
>
>
>At 11:22 PM 5/28/2002 +0200, you wrote:
> >It not only thinks you are trying to open it again, it knows THAT you
>are
> >opening it again ;-)
> >
> >
> >Take a look at this:
> >
> >' First sproc
> >>             Try
> >>                dbconn.Open()
> >>                dr =3D cmd.ExecuteReader
> >
> >
> >' Second sproc
> >>             Try
> >>                dbconn.Open()
> >>                dr =3D cmd.ExecuteReader()
> >
> >
> >Hmmm, too much caffeine?? ;-)
> >
> >
> >
> >Imar
> >
> >
> >At 02:15 PM 5/28/2002 -0700, you wrote:
> >>I have a page load procedure where
> >>1. if user is valid call stored procedure
> >>2. within that if statement, if not page.ispostback call another
>stored
> >>procedure.
> >>
> >>I am getting the following error: An error has occurred:
> >>System.InvalidOperationException: The connection is already Open
> >>(state=3DOpen). at System.Data.SqlClient.SqlConnection.Open() at
> >>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
> >>
> >>I partially understand what is going on, but I can find where to fix
>it.
> >>To my knowledge I leave the connection object open and available for
>the
> >>second stored procedure when calling the first.  Somewhere it thinks
I
> >>not only left it open but I am trying to open it again.  I tried
>remming
> >>out the dbconn.Open() in the second stored procedure, but then I get
> >>another error:
> >>
> >>An error has occurred: System.Data.SqlClient.SqlException: Procedure
> >>sp_CompanyList has no parameters and arguments were supplied. at
> >>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> >>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
> >>System.Data.SqlClient.SqlCommand.ExecuteReader() at
> >>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
> >>
> >>I have included my code below.  If someone could take a quick glance
>at
> >>it I'd really, really appreciate it.
> >>
> >>
> >>
> >>    Sub Page_Load(s As Object, e As EventArgs)
> >>
> >>       If User.Identity.IsAuthenticated Then
> >>          displayCredentials.InnerHtml =3D "Current User: " &
> >>User.Identity.Name
> >>
> >>             Dim dbconn As SqlConnection =3D New SqlConnection _
> >>
>(ConfigurationSettings.AppSettings("ConnectionString"))
> >>
> >>             Dim cmd As SqlCommand =3D New
SqlCommand("sp_ReqsEntered",
> >>dbconn)
> >>                cmd.CommandType =3D CommandType.StoredProcedure
> >>
> >>             Dim reqByParam As SqlParameter =3D
> >>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
> >>             reqByParam.Direction =3D ParameterDirection.Input
> >>             reqByParam.Value =3D CStr(User.Identity.Name)
> >>
> >>             Dim dr As SqlDataReader
> >>
> >>             Try
> >>                dbconn.Open()
> >>                dr =3D cmd.ExecuteReader
> >>                'dr =3D
>cmd.ExecuteReader(CommandBehavior.CloseConnection)
> >>
> >>                lstTodaysReqs.DataSource =3D dr
> >>                lstTodaysReqs.DataBind()
> >>
> >>             Catch exc As Exception
> >>                Response.Write("An error has occurred: " &
> >>exc.ToString())
> >>
> >>             Finally
> >>                If Not dr is Nothing Then
> >>                   dr.Close()
> >>                End If
> >>
> >>             End Try
> >>
> >>          If Not Page.IsPostBack Then
> >>
> >>             'Dim dbconn As SqlConnection =3D New SqlConnection _
> >>
>'(ConfigurationSettings.AppSettings("ConnectionString"))
> >>
> >>             'Dim cmd As SqlCommand =3D New SqlCommand()
> >>             With cmd
> >>                .Connection =3D dbconn
> >>                .CommandText =3D "sp_CompanyList"
> >>                .CommandType =3D CommandType.StoredProcedure
> >>             End With
> >>
> >>             'Dim dr As SqlDataReader
> >>
> >>             Try
> >>                dbconn.Open()
> >>                dr =3D cmd.ExecuteReader()
> >>                'dr =3D
>cmd.ExecuteReader(CommandBehavior.CloseConnection)
> >>
> >>                lstCompany.DataSource =3D dr
> >>                lstCompany.DataBind()
> >>
> >>             Catch exc As Exception
> >>                Response.Write("An error has occurred: " &
> >>exc.ToString())
> >>
> >>             Finally
> >>                If Not dr is Nothing Then
> >>                   dr.Close()
> >>                End If
> >>
> >>                lstCompany.Items.Insert(0, "not selected")
> >>                   lstCompany.SelectedIndex =3D 0
> >>                   lstCompany.SelectedItem.Value =3D 0
> >>                   lstCompany.SelectedItem.Text =3D "not selected"
> >>
> >>             End Try
> >>
> >>          End If
> >>
> >>       Else
> >>          displayCredentials.InnerHtml =3D "You must be an
authenticated
> >>user prior to using this service."
> >>       End If
> >>
> >>    End Sub
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >---
> >Change your mail options at http://p2p.wrox.com/manager.asp or to
> >unsubscribe send a blank email to 
>
>
>
>



Message #8 by "Farrell, Timothy" <Timothy.Farrell@C...> on Wed, 29 May 2002 12:51:15 -0400
Imar,

Please see latest post.

Sorry about your day.  I'll keep it short today.

Regards,

Tim

-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Wednesday, May 29, 2002 12:36 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: connection problems


Hi Chris,

Sorry for the late reaction. I had quite a busy day today.

Do you use IsPostBack in your code? Did you enable caching of any kind?
Usually, you should be able to retrieve the new records, as the query 
should execute every time you request the page.

If this doesn't work, post the relevant parts of the page (including 
pageheader directives and code behind) so we can take a look at it.

Imar


At 02:53 PM 5/28/2002 -0700, you wrote:
>Hi Imar,
>
>Thanks - I used .Parameters.Remove(ReqByParam) and it works now.
>
>Since you have read through my code I was wondering if you might be able
>to offer some more advice:
>
>The first stored procedure builds a list of submitted requests by the
>logged in user.  My intent is for the list to grow as the user submits
>requests, so they can see what they have submitted so far.
>
>I loaded this sproc on page load thinking it would refresh the list on
>page load and postback.  However, this doesn't work quite right.  Say I
>save one record.  Nothing happens.  I save a second and the first record
>appears in the list.  It lags one record behind - the only way to make
>the last record show right after clicking the submit button is to click
>refresh on the browser.
>
>I tried stating autopostback = true for the submit button.  Didn't work.
>Do I need to also specify response.redirect to the same page on button
>click to make my code work?  Can you help me?
>
>Thanks,
>
>John
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, May 28, 2002 2:35 PM
>To: aspx_beginners
>Subject: [aspx_beginners] Re: connection problems
>
>Whoops, just realized that -I- didn't read good enough :-( Sorry.
>
>The cmd object still has the parameter assigned from the first command
>object. You should either remove these (look at
>Command.Parameters.Remove()
>and Command.Parameters.RemoveAt()), or easier yet, just create a second
>command object. I think when you reuse the connection, the overhead of
>creating a second command object is rather minimal.
>
>HtH
>
>
>Imar
>
>
>At 11:22 PM 5/28/2002 +0200, you wrote:
> >It not only thinks you are trying to open it again, it knows THAT you
>are
> >opening it again ;-)
> >
> >
> >Take a look at this:
> >
> >' First sproc
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader
> >
> >
> >' Second sproc
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader()
> >
> >
> >Hmmm, too much caffeine?? ;-)
> >
> >
> >
> >Imar
> >
> >
> >At 02:15 PM 5/28/2002 -0700, you wrote:
> >>I have a page load procedure where
> >>1. if user is valid call stored procedure
> >>2. within that if statement, if not page.ispostback call another
>stored
> >>procedure.
> >>
> >>I am getting the following error: An error has occurred:
> >>System.InvalidOperationException: The connection is already Open
> >>(state=Open). at System.Data.SqlClient.SqlConnection.Open() at
> >>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
> >>
> >>I partially understand what is going on, but I can find where to fix
>it.
> >>To my knowledge I leave the connection object open and available for
>the
> >>second stored procedure when calling the first.  Somewhere it thinks I
> >>not only left it open but I am trying to open it again.  I tried
>remming
> >>out the dbconn.Open() in the second stored procedure, but then I get
> >>another error:
> >>
> >>An error has occurred: System.Data.SqlClient.SqlException: Procedure
> >>sp_CompanyList has no parameters and arguments were supplied. at
> >>System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> >>cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
> >>System.Data.SqlClient.SqlCommand.ExecuteReader() at
> >>ASP.RequestClaimRemoval_aspx.Page_Load(Object s, EventArgs e)
> >>
> >>I have included my code below.  If someone could take a quick glance
>at
> >>it I'd really, really appreciate it.
> >>
> >>
> >>
> >>    Sub Page_Load(s As Object, e As EventArgs)
> >>
> >>       If User.Identity.IsAuthenticated Then
> >>          displayCredentials.InnerHtml = "Current User: " &
> >>User.Identity.Name
> >>
> >>             Dim dbconn As SqlConnection = New SqlConnection _
> >>
>(ConfigurationSettings.AppSettings("ConnectionString"))
> >>
> >>             Dim cmd As SqlCommand = New SqlCommand("sp_ReqsEntered",
> >>dbconn)
> >>                cmd.CommandType = CommandType.StoredProcedure
> >>
> >>             Dim reqByParam As SqlParameter 
> >>cmd.Parameters.Add("@reqBy", SqlDbType.VarChar, 15)
> >>             reqByParam.Direction = ParameterDirection.Input
> >>             reqByParam.Value = CStr(User.Identity.Name)
> >>
> >>             Dim dr As SqlDataReader
> >>
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader
> >>                'dr 
>cmd.ExecuteReader(CommandBehavior.CloseConnection)
> >>
> >>                lstTodaysReqs.DataSource = dr
> >>                lstTodaysReqs.DataBind()
> >>
> >>             Catch exc As Exception
> >>                Response.Write("An error has occurred: " &
> >>exc.ToString())
> >>
> >>             Finally
> >>                If Not dr is Nothing Then
> >>                   dr.Close()
> >>                End If
> >>
> >>             End Try
> >>
> >>          If Not Page.IsPostBack Then
> >>
> >>             'Dim dbconn As SqlConnection = New SqlConnection _
> >>
>'(ConfigurationSettings.AppSettings("ConnectionString"))
> >>
> >>             'Dim cmd As SqlCommand = New SqlCommand()
> >>             With cmd
> >>                .Connection = dbconn
> >>                .CommandText = "sp_CompanyList"
> >>                .CommandType = CommandType.StoredProcedure
> >>             End With
> >>
> >>             'Dim dr As SqlDataReader
> >>
> >>             Try
> >>                dbconn.Open()
> >>                dr = cmd.ExecuteReader()
> >>                'dr 
>cmd.ExecuteReader(CommandBehavior.CloseConnection)
> >>
> >>                lstCompany.DataSource = dr
> >>                lstCompany.DataBind()
> >>
> >>             Catch exc As Exception
> >>                Response.Write("An error has occurred: " &
> >>exc.ToString())
> >>
> >>             Finally
> >>                If Not dr is Nothing Then
> >>                   dr.Close()
> >>                End If
> >>
> >>                lstCompany.Items.Insert(0, "not selected")
> >>                   lstCompany.SelectedIndex = 0
> >>                   lstCompany.SelectedItem.Value = 0
> >>                   lstCompany.SelectedItem.Text = "not selected"
> >>
> >>             End Try
> >>
> >>          End If
> >>
> >>       Else
> >>          displayCredentials.InnerHtml = "You must be an authenticated
> >>user prior to using this service."
> >>       End If
> >>
> >>    End Sub
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >---
> >Change your mail options at http://p2p.wrox.com/manager.asp or to
> >unsubscribe send a blank email to 
>
>
>
>






The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it. 

Message #9 by Imar Spaanjaars <Imar@S...> on Wed, 29 May 2002 19:43:34 +0200
Hi John,

Sorry about the name mix up. Must have been looking at the wrong message in 
the message list while replying ;-)

Anyway, it seems weird that it doesn't show the records. What you could do 
is separate the procedure that does the binding. So for instance 
(abbreviated versions of the Subs you could create):


Sub BindMyDataList()
         ' do binding here
End Sub

Sub Page_Load()
         If Not Page.IsPostBack Then
                 BindMyDataList()
         End if
End Sub

Sub Button1_OnClick()
         ' Do stuff to insert the record
         ' Rebind the datalist
         BindMyDataList()
End Sub


IMO, this should produce the right results: first, it will load the list 
when the page is hit for the first time. Then, it will also load the list 
after an insert has been made.

If this doesn't work, please indeed post some of your code.

HtH


Imar


At 09:48 AM 5/29/2002 -0700, you wrote:
>Hi Imar,
>
>Thanks for responding.  I'm John though ;-)  I have a brother named
>Chris...but probably not the Chris whose posts you have been responding
>to.
>
>I only use IsPostBack to load dropdownlist values on page load (If Not
>Page.IsPostBack Then...) - so no.  Don't use AutoPostBack = "true" in
>this page either, and am not working with caching at all.
>
>I had assigned the procedure to call the requests list to the submit
>button OnClick event, but that's where I ran into the problem that the
>list would only update every two button clicks, and when it did refresh
>it would show the record entered two clicks ago but not the most current
>submission.
>
>I moved the procedure to page_load, but in order to make it refresh I
>had to add a response.redirect back to the same page.  I don't think
>this is the correct approach because I don't want to hit the server each
>time - but does this actually create more work for the server if a new
>record is being submitted to the database anyway?
>
>If you want I can change my code back to the way I had it originally and
>post it for you to look at.
>
>Thanks,
>
>John


Message #10 by Imar Spaanjaars <Imar@S...> on Wed, 29 May 2002 22:03:49 +0200
Just to expand on this a little, it makes sense when you think about the 
order of events.
Page_Load is called before the Button_Click fires. That means that your 
dropdown has been populated BEFORE you insert the record in the click event 
of the button.
That also explains why you can see the record in the list after you refresh 
or do a "redirect" to itself.

To see this behavior, create a simple page with just a button and a label. 
Add the following code:

     Public MyBool As Boolean = False
     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
         MyBool = True
     End Sub

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button1.Click
         Label1.Text = MyBool
     End Sub

When you first load the page, the label will be blank (which makes sense). 
If you press the button, Page_Load is called and the Boolean is set to 
true. Then the label will be filled in the Button1_Click event with the 
current value of the Boolean (True).

Hope this clarifies things a little more.

Imar


At 07:43 PM 5/29/2002 +0200, you wrote:
>Hi John,
>
>Sorry about the name mix up. Must have been looking at the wrong message 
>in the message list while replying ;-)
>
>Anyway, it seems weird that it doesn't show the records. What you could do 
>is separate the procedure that does the binding. So for instance 
>(abbreviated versions of the Subs you could create):
>
>
>Sub BindMyDataList()
>         ' do binding here
>End Sub
>
>Sub Page_Load()
>         If Not Page.IsPostBack Then
>                 BindMyDataList()
>         End if
>End Sub
>
>Sub Button1_OnClick()
>         ' Do stuff to insert the record
>         ' Rebind the datalist
>         BindMyDataList()
>End Sub
>
>
>IMO, this should produce the right results: first, it will load the list 
>when the page is hit for the first time. Then, it will also load the list 
>after an insert has been made.
>
>If this doesn't work, please indeed post some of your code.
>
>HtH
>
>
>Imar


Message #11 by "John Tyson" <jtyson@t...> on Wed, 29 May 2002 13:29:31 -0700
Hi Imar,

Thank you for the explanation.  I think I understand a little better the
lifecycle of an aspx page.

The way I finally got this working to my satisfaction was to call the
stored procedure that pulls up the requests posted list in the page_load
event, and then to also call that stored procedure in the submit OnClick
event - that way it refreshes my DataList without having to reload the
entire page.  Might not be the cleanest way of doing things but it works
much nicer and probably reduces the page trips to the server two to
three times.

Any future advice suggestions are very welcome.  Thanks again,

John


-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Wednesday, May 29, 2002 1:04 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: connection problems

Just to expand on this a little, it makes sense when you think about the

order of events.
Page_Load is called before the Button_Click fires. That means that your
dropdown has been populated BEFORE you insert the record in the click
event
of the button.
That also explains why you can see the record in the list after you
refresh
or do a "redirect" to itself.

To see this behavior, create a simple page with just a button and a
label.
Add the following code:

     Public MyBool As Boolean =3D False
     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
         MyBool =3D True
     End Sub

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click
         Label1.Text =3D MyBool
     End Sub

When you first load the page, the label will be blank (which makes
sense).
If you press the button, Page_Load is called and the Boolean is set to
true. Then the label will be filled in the Button1_Click event with the
current value of the Boolean (True).

Hope this clarifies things a little more.

Imar


At 07:43 PM 5/29/2002 +0200, you wrote:
>Hi John,
>
>Sorry about the name mix up. Must have been looking at the wrong
message
>in the message list while replying ;-)
>
>Anyway, it seems weird that it doesn't show the records. What you could
do
>is separate the procedure that does the binding. So for instance
>(abbreviated versions of the Subs you could create):
>
>
>Sub BindMyDataList()
>         ' do binding here
>End Sub
>
>Sub Page_Load()
>         If Not Page.IsPostBack Then
>                 BindMyDataList()
>         End if
>End Sub
>
>Sub Button1_OnClick()
>         ' Do stuff to insert the record
>         ' Rebind the datalist
>         BindMyDataList()
>End Sub
>
>
>IMO, this should produce the right results: first, it will load the
list
>when the page is hit for the first time. Then, it will also load the
list
>after an insert has been made.
>
>If this doesn't work, please indeed post some of your code.
>
>HtH
>
>
>Imar




  Return to Index