Re: What to do when you can't retrieve content from a DB



Thanks for that response, sets me right back on track. Oh for the love
of learning through mistakes.

On Jul 10, 9:05 pm, "Bob Barrows [MVP]" <reb01...@xxxxxxxxxxxxxxx>
wrote:
thewinchesterwrote:
I've got something bugging me and as i'm not a hard core programmer
its got me beat - anyone who can point me in the right direction or
help me solve it would be my hero for at least the next five minutes.

Ok, here's the scenario - a corporate intranet, where selected pages
have parts of information that come from a database such as news
articles or an events calendar. Due to the geographic spread of the
organisation, the physical ASP pages are mirrored out to the remote
sites via DFS and the address for the intranet has a local alias which
accesses the copy from the local IIS server.

However, when the SQL server goes down or the sites lose their
internet connectivity, pages pulling dynamic content will return
errors. Ideally, when the page loads and it's unable to connect to the
DB, it would skip running the code, repeats, etc and instead return a
message in place such as "DB not available, try again later".

SQL connection strings for pages are available from both web.config
and an include file.

My questions:

1) How do I stop the SQL queries from running in the event that
communication with the SQL server is not possible.

Wait a minute, you seem to be contradicting yourself. You said above that
the pages would return errors. Now you are implying that the sql queries are
attempted to be run even when the errors occur? Not possible. This sounds
like a case for simple error trapping:

on error resume next
cn.open ...
if err<> 0 then
    'display connection problem message
else
    'execute your sql
    if err <> 0 then
    ...
end if

2) How can the loss of connection be detected, so that the static
portions of the page display as normal and the dynamic data-driven
content displays an error message in place instead of trying to run
the code and causing SQL OLE DB provider errors?

See above.

You should not be attempting to "stay connected" as your "loss of
connection" phrase implies. Your procedure should be:

when a page loads, attempt to open the connection
if successful run your code
close your connection as soon as you can

If you are "losing connection" in the few ms or seconds that your
server-side code is processing, then you have real network issues that your
IT people need to take care of.

If your server-side code takes longer than a few seconds to process, then i
suggest you look at optimizing what you are doing. Consider using GetString
or GetRows to allow you to quickly pull your data into a string or array,
allowing you to close your recordset and connection immediately before
processing the data in the string or array.http://www.aspfaq.com/show.asp?id=2467

If that is not feasible, and you need to keep your recordset open for
lengthy time periods, use client-side, disconnected recordsets:

set rs=createobject("adodb.recordset")
rs.cursorlocation=3 'adUseClient
rs.Open sql, cn,,,1
set rs.activeconnection = nothing
cn.close
'process the recordset

And a bonus question:

3) What's the best way to mitigate for connection loss in this
environment? Should I be looking at caching the output of these parts
on a frequent basis and reading these in each time the page is loaded,
and what's the best method to do it.

Caching is certainly doable. You can use either Application or Session
variables.http://msdn2.microsoft.com/en-us/library/ms524664.aspx

Or write content to a text file on the web server, refreshing it
periodically.

It all depends on how often that content changes, and how often these
problems occur. Caching consumes server resources, so it's a balancing act
deciding how much data to cache.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

.



Relevant Pages

  • Re: Connection issues between .Net framwok and SQl Express 2005
    ... You will no longer need the database MDF file name in the connection string. ... simply attach the ASPNETDB.mdf to SQL Server permenantly, ... as USER INSTANCE on existing SQL Server Express, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Performance of ODBC
    ... if you have a software firewall; forward 1433/1434 to your server ... I've now created my own server with SQL Server 2005 Express, ... glitch concerns the Upsizing Wizard. ... I originally set up my ODBC connection via ...
    (microsoft.public.access.adp.sqlserver)
  • SQL 2005 Express and VS .Net 2003 wizard error More options
    ... Open the server explorer panel ... Go to the Provider tab and select SQL NAtive Client (DON'T use oledb ... Go back to the Connection tab and carry on setting up the connection ... I have installed Visual Studio 2005 Professional and then Visual Studio ...
    (microsoft.public.sqlserver)
  • Re: ASP - FROM statement slows down connection to database
    ... Open your database in Access, switch to the Queries tab, create a new query ... in Design View without choosing a table, swtich to SQL View, paste the sql ... connection string rather than using an ... recordset open statements. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Timeout problem with SS2K, VS03
    ... I noticed calls in sql profiler: ... This is the server side debug stored procedure. ... a timeout issue that I cannot identify the source of. ... transaction is committed and the connection is closed cleanly and all ...
    (microsoft.public.dotnet.framework.adonet)

Loading