Ignoring a bad connection

Results 1 to 3 of 3

Thread: Ignoring a bad connection

  1. #1
    Join Date
    Dec 1969

    Default Ignoring a bad connection

    Can I use On Error Resume Next to move on when a db connection cannot be made? I&#039;ve tried to use it by intentionally plugging in a bad IP address. Here&#039;s a basic example of what I&#039;m trying:<BR>================================<BR>Sub goFish()<BR> On Error Resume Next<BR><BR> Set conn = Server.CreateObject("ADODB.Connection")<BR> connection_string = "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=;DATABASE=dbname;UID=uid ;PWD=pwd;"<BR> conn.Open connection_string<BR><BR> &#039;misc processing here that uses the db<BR>End Sub<BR><BR>Call goFish()<BR>====================================== ====<BR><BR>I was hoping the sub would quit instantly when it realized a connection could not be made. Instead, it just chugs away trying to connect. Is there maybe a way to ping it instead? My goal, in this case, is for the whole sub to say "forget it" if no connection is made. <BR><BR>This script is used to display ads. Lately my db server has become more and more unavailable (a separate issue for me to address), and when it&#039;s down, pages that use this connection cannot be displayed. I&#039;d rather skip displaying the dynamic content than prevent showing the whole page when this happens. For the most part, I&#039;m talking about ads that run. I&#039;d rather have a blank spot on the page than for someone to have no access at all.<BR><BR>Any suggestions?<BR><BR>Thanks a lot!

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Dont ignore...make it stand in a corner

    the only way is open the connection...check for error...if error redirect to error page<BR><BR><BR><BR>if you move on then you will be trying to open a recordset or execute something and that will fail again<BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Slight improvement...

    If you really don&#039;t care about the results of the SUB call when something goes wrong...<BR><BR>Then, yes, do the ON ERROR RESUME NEXT.<BR><BR>And check for an error after each DB operation.<BR><BR>And if you get an error...Simply do<BR>&nbsp; &nbsp; EXIT SUB<BR>!!! <BR><BR>The SUB won&#039;t write anything to the HTML page, but you said that&#039;s okay.<BR><BR>Note that an ON ERROR trap only lasts for the duration of a SUB or FUNCTION, so you don&#039;t even need to reset it when you leave the sub/function.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts