locked
My site is posting twice. RRS feed

  • Question

  • User-944633366 posted

    Hello. I posted this on a MSSQL forum, went through it a bit, then they told me (2019 is so funny) they don't know anything about asp.net. 

    Can someone please help me here? Thanks.

    Bottom line... After moving my MSSQL server away from the same machine as my IIS server (they're on two machines now, in different parts of the country, connecting over the public internet). .... Sometimes (I'm guessing at high latency times of the day like early morning when I see it)........... If I post to my site.... IT POSTS Twice which gets annoying (posting meaning to execute an SP twice, that's all it's doing). I click once, it hits the SP twice. No code changes since I moved it. And it worked fine on the same server for over a year.

    Original thread: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/dcbc9a7b-3a2d-4238-8113-9038e1742d1c/why-remote-mssql-server-posting-back-twice-but-local-is-not?forum=sqlnetfx

    Thursday, June 27, 2019 11:27 AM

All replies

  • User475983607 posted

    Hello. I posted this on a MSSQL forum, went through it a bit, then they told me (2019 is so funny) they don't know anything about asp.net. 

    Can someone please help me here? Thanks.

    Bottom line... After moving my MSSQL server away from the same machine as my IIS server (they're on two machines now, in different parts of the country, connecting over the public internet). .... Sometimes (I'm guessing at high latency times of the day like early morning when I see it)........... If I post to my site.... IT POSTS Twice which gets annoying (posting meaning to execute an SP twice, that's all it's doing). I click once, it hits the SP twice. No code changes since I moved it. And it worked fine on the same server for over a year.

    Original thread: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/dcbc9a7b-3a2d-4238-8113-9038e1742d1c/why-remote-mssql-server-posting-back-twice-but-local-is-not?forum=sqlnetfx

    Double inserts indicates an bug in the code.  The things we see most often on the forum is a double tap on the submit button or the submit button invokes an AJAX POST as well as an HTML form submit.  Sometimes we see double event wire ups which generally happens in VB.NET Web Forms.

    If you share your code, that causes this issue, we can take a look and fix you up.  Otherwise, the browser's dev tools (F12) has a network trace that will show if the browser is sending two POST requests.  That should get you started down the troubleshooting path.

    Thursday, June 27, 2019 11:50 AM
  • User-944633366 posted

    I don't understand how it could be "double post," by any native way.

    1.) I have the submit using a javascript "confirm" button. Pressing, "OK" only submits it.

    2.) This page worked perfectly fine for almost exactly one solid year when IIS and MSSQL were on the same box.

    The only variable that changed was me moving them apart (geographically, aka: public internet).

    Moreoever, I see this issue almost exclusively in the 8:30-10:30 ET hours which as we know is when traffic on the internet is very high, and latency among some providers is very low. 

    Any ideas?

    Thursday, June 27, 2019 7:52 PM
  • User475983607 posted

    jbassett

    I don't understand how it could be "double post," by any native way.

    1.) I have the submit using a javascript "confirm" button. Pressing, "OK" only submits it.

    2.) This page worked perfectly fine for almost exactly one solid year when IIS and MSSQL were on the same box.

    The only variable that changed was me moving them apart (geographically, aka: public internet).

    Moreoever, I see this issue almost exclusively in the 8:30-10:30 ET hours which as we know is when traffic on the internet is very high, and latency among some providers is very low. 

    Any ideas?

    I provided my ideas above; usually double POSTs is a bug.  The browser is sending multiple requests, server side event handler firing twice or a misbehaving loop.

    I've never experienced double INSERTs due to the Internet being busy.  I'm not sure how a busy network would duplicate INSERTs.  Setup a network trace between 8:30 and 10:30 and log the traffic.

    Thursday, June 27, 2019 8:31 PM
  • User-944633366 posted

    I provided a trace in that example. It's almost as if the IIS server "can't quite see MSSQL and there is no failsafe" so it just "tries again,." Is it possible IIS natively is just buggy like that?  The question is, is-that what it's doing?

    Meaning: Should there be some ack back from MSSQL before IIS sends the SP? Is this something (some failsafe) we could add to the .net code? Meaning, some type of... "don't send the execute sp request if you sent it once until you hear back."

    What I know is nothing changed, and it worked beautifully for over one year and at least 2,000 active postings (executing of the sp via the vb.net/asp.net code).

    Does the SQL server need to be "linked" in some way? As of now I'm connecting via .dbml with the definitions in web.config.

    Friday, June 28, 2019 11:47 AM
  • User475983607 posted

    I provided a trace in that example.

    No a network trace or SQL logging.

    It's almost as if the IIS server "can't quite see MSSQL and there is no failsafe" so it just "tries again,." Is it possible IIS natively is just buggy like that?  The question is, is-that what it's doing?

    Meaning: Should there be some ack back from MSSQL before IIS sends the SP? Is this something (some failsafe) we could add to the .net code? Meaning, some type of... "don't send the execute sp request if you sent it once until you hear back."

    IIS handles HTTP requests. IIS does not open a connection to the DB, your code does.  

    What I know is nothing changed, and it worked beautifully for over one year and at least 2,000 active postings (executing of the sp via the vb.net/asp.net code).

    If I only had a dollar for every time I hear nothing changed.  

    Does the SQL server need to be "linked" in some way? As of now I'm connecting via .dbml with the definitions in web.config.

    I have no idea what you are asking.  A dbml file is a UI interface that shows your LINQ to SQL Entities and related Entities.  The actual connection is standard ADO.NET.

    Friday, June 28, 2019 12:11 PM
  • User753101303 posted

    Hi,

    So you tried to see if you have two http requests? Sometimes it is the handler which is mistakenly binded twice to the same event (so you have one http request and the handler is called twice). Sometimes it is an ajax request on a submit button and this event not being properly cancelled (so you really have two http requests).

    You may ask why it worked before but it is basically irrelevant. See first why it doesn't work as expected now...

    Friday, June 28, 2019 12:11 PM
  • User-944633366 posted

    I've been developing over 30 years. I don't have the answer but my questions are founded and legitimate.

    Friday, June 28, 2019 4:37 PM
  • User-944633366 posted

    I'll keep looking. Nothing in the code changed, except the web.config pointer to the new server. I'll try some other traces. It is weird. But you don't think I need to "link it" in some way? Just .dbml (instead of the old way, calling it all in code) and web.config? 

    Friday, June 28, 2019 4:39 PM
  • User-944633366 posted

    Maybe I did need some code from the beginning (likely so as I stated from the beginning) but How did "moving the servers apart" (the only variable introduced) exacerbate this problem? It must have, and that is where to find the answer. So that point should not only not be dismissed, it should be lauded. 

    Friday, June 28, 2019 4:43 PM
  • User475983607 posted

    I'll keep looking. Nothing in the code changed, except the web.config pointer to the new server. I'll try some other traces. It is weird. But you don't think I need to "link it" in some way? Just .dbml (instead of the old way, calling it all in code) and web.config? 

    I'm not sure what you are asking.  a .dbml file is designer file that provides a UI interface for code generation. 

    Maybe I did need some code from the beginning (likely so as I stated from the beginning) but How did "moving the servers apart" (the only variable introduced) exacerbate this problem? It must have, and that is where to find the answer. So that point should not only not be dismissed, it should be lauded. 

    Sure, separating the Web Application and Database server could expose the bug.   

    The first step in troubleshooting is reproducing the behavior.  Once you can reproduce the problem then you should be able to isolate the code path.

    We cannot reproduce your environment and therefore cannot troubleshoot this issue.   We can only fall back on our experiences.  I have never witnessed duplicate INSERTs due to Internet traffic or using a 2-tier design.  

    Friday, June 28, 2019 5:19 PM
  • User753101303 posted

    As it seems you have a SP that runs twice, you could check :
    - is this really the case ? (if you INSERT based on other tables a wrong JOIN could  maybe cause duplicated rows to be inserted)
    - if ok, I would check if I have two http requests or if the handler is called twice for a single http request

    Most often this kind of issue happens (it always happen or in rare cases ?) when a user is clicking twice or is refreshing the page causing another POST (depending on how your page is done).

    In short don't stop at looking that you insert a row twice and then immediately wonder what could cause this . Instead look at what your code does exactly to cause this double insert. Then you should quickly find the root cause.

    Wednesday, July 3, 2019 11:05 AM