Dear God text-wrapping at 76 characters gives me a really bad hair day.
The most obvious one that may catch you out is this line:
pstrConnectionString = pstrConnectionString & ";Data Source=" &
pstrDatabaseFilePathNameLocal
It should all be on one line.
Chris.
No-one really seems to have bothered trying to explain whats going on which
means that Ray is effectively coding and debugging blind?
Ray, use this code and carefully consider each step.
<%
Option Explicit
'Option explicit ensures that an error will be generated when
'attempting to access a variable that has *not* been declared
Dim pobjConnection 'The connection object - if an error occurs this will
be set to Nothing
Dim pstrConnectionString 'Connection string that defines the connection
properties.
'The URL that would correspond to the database if accessed through the web
browser.
Dim pstrDatabaseURL
'The filepathname where the DB resides *on* the webserver as defined by the
local file system.
Dim pstrDatabaseFilePathNameLocal
'The database OLEDB provider
Dim pstrDatabaseProvider
'Define and initialise the connection object (not connected to the DB yet
but exists as an object).
Set pobjConnection = Server.CreateObject("ADODB.Connection")
'Now we define the connection string from a couple of key variables.
pstrDatabaseURL = "\fpdb\books.mdb"
pstrDatabaseProvider = "Microsoft.Jet.OLEDB.4.0"
'Let IIS convert this database URL into a local filesystem path since that's
what ADO expects.
pstrDatabaseFilePathNameLocal = Server.MapPath(pstrDatabaseURL)
'Generate the connection string being careful with the syntax.
pstrConnectionString = "Provider=" & pstrDatabaseProvider
pstrConnectionString = pstrConnectionString & ";Data Source=" &
pstrDatabaseFilePathNameLocal
'You may want to debug these values here before continuing - this line will
report the connection string.
Response.Write("ConnectionString = '" & pstrConnectionString & "'<br/>")
'Try to open the connection now and catch any errors.
On Error Resume Next
pobjConnection.Open(pstrConnectionString)
'Display the error information if required.
If Err.Number <> 0 Then
Response.Write "Open connection returned an error.<br/>"
Response.Write "Description: " & Err.Description
Err.Clear
End If
'Reset the error handling again to the normal method (raise error).
On Error Goto 0
If Not(pobjConnection Is Nothing) Then
Response.Write "Connection successfully opened.<br/>"
Else
Response.Write "No error reported but the connection object returned as
[Nothing].<br/>"
End If
'Now close the connection - not really required but it's good practice.
pobjConnection.Close
Set pobjConnection = Nothing
%>
Keep in mind that this is *all* occurring on the webserver as if you were
sat at it executing the script yourself (security implications aside).
Also be very careful that the posted script is not broken due to line
wrapping at 76 characters (news posts do this).
There is a chance that if your MDB is outside the web structure that the
current context user for the ASP session may not have sufficient rights to
access it. It's more secure to have it outside the web structure but more
difficult to maintain remotely.
Hope this helps,
Chris.
.....now it says
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Websites\hdo212\notjustbooks\fpdb\books.mdb
which is wrong! It seems to be looking on my local system rather than my web
server. But it's progress!
Bob Barrows said:
Oops - I forgot to correct your slashes. Server.MapPath requires a url as
the argument.
Not this:
This:
sConnect ="Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/fpdb/books.mdb")
This line needs to go:
**************************************
That error is covered is in this article:
http://www.aspfaq.com/show.asp?id=2009 - 80004005 errors
HTH,
Bob Barrows
--
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"