New problem

B

BD

I'm trying to build a hit counter that does what I want using an Access
database named counters.mdb which contains 2 tables. The only one involved
here is page_count. Here is the code for the aspx test page.
===============================
<%@ Page Language="VB" Debug="true" runat="server"%>
<%@ import Namespace="System.Data.OLEDB" %>

<script runat="server" language="vb">
Function pCount()
Const adOpenKeyset = 1
Const adLockPessimistic = 2
Const adCmdText = &H0001
Dim hCount As Integer
Dim sPage = Request.FilePath.Remove(0,Request.FilePath.LastIndexOf("/")
+1)
Dim sCmd = "SELECT * FROM page_count WHERE pagename='" & sPage & "';"
Dim dSource As String = Server.MapPath("counters.mdb"), sTest As String =
""
Dim rsCounter = Server.CreateObject("ADODB.Recordset")
rsCounter.Open(sCmd, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
dSource & ";", _
adOpenKeyset, adLockPessimistic, adCmdText)
If rsCounter.EOF Then
sTest = "EOF has been reached."
'rsCounter.AddNew() 'uncommenting this line will throw an error
'rsCounter.Fields("pagename").Value = sPage
End If
rsCounter.Close()
rsCounter = nothing
Dim rTxt = "<p>The database path is: " & dSource & "</p><p>" & sTest &
"</p><p>The page is: " & sPage & "</p>"
Return rTxt
End Function
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Hit Counter Test</title>
</head>
<body>
<%Response.write(pCount())%>
</body>
</html>
=========================================
This produces the correct output, however if I uncomment the line
rsCounter.AddNew()
it starts throwing the following error
System.Runtime.InteropServices.COMException: Cannot update. Database or
object is read-only.

Could someone please tell me what is wrong? I've been at this since
yesterday.
If I have posted this in the wrong group then please direct me to the right
one
Thanks
 
B

Bob Barrows [MVP]

BD said:
I'm trying to build a hit counter that does what I want using an
Access database named counters.mdb which contains 2 tables. The only
one involved here is page_count. Here is the code for the aspx test
page.

There was no way for you to know it (except maybe by browsing through
some of the previous questions before posting yours - always a
recommended practice), but this is a classic asp newsgroup. ASP.Net is
a different technology from classic ASP. While you may be lucky enough
to find a dotnet-savvy person here who can answer your question, you
can eliminate the luck factor by posting your question to a newsgroup
where the dotnet-savvy people hang out. I suggest
microsoft.public.dotnet.framework.aspnet.
There are also forums at www.asp.net where you can find a lot of people
to help you.

HTH,
Bob Barrows
 
B

BD

Thanks Bob.
As a former MVP myself I should have known to look for more news groups.
 
B

Bob Barrows [MVP]

I meant to post the solution - hopefully you are still reading:
BD said:
Dim rsCounter = Server.CreateObject("ADODB.Recordset")

Err ... you really should be using ADO.Net rather than ADO.
System.Runtime.InteropServices.COMException: Cannot update. Database
or object is read-only.
This is always file-system-permissions-related. All users of an mdb file
require Modify permissions for the _folder_ containing the database.
This is to allow users to create, modify and delete the jet locking file
(.ldb) that controls multi-user access to the mdb file
 
B

BD

I'm still reading, thanks Bob.
I am still new to ASP and ASP.NET so I will need some hand holding here. I
don't understand what you have stated in your reply. How would I go about
doing this? Bear in mind that I am testing on IIS 6 and eventually the file
has to be uploaded to a Server 2003 system. All I need is a simple page hit
counter (database). The remaining table in my database is for tracking file
downloads so I'm thinking that If I can get the page hit to work, then the
downloads counter will be easier.
Do you have a web site on the mvps (Karls) server? Yes or no will probably
suffice. I should be able to find it from there.
 
B

Bob Barrows [MVP]

It's file-system permissions. Right-click the folder in windows
explorer, choose Security and assign Modify permissions to the users of
the database. Who the users that need permissions are depends on how
your website is configured to authenticate:
Anonymous means the aspnet account is the user
Integrated with Anonymous disabled means the network user is the user

I have no website on mvps.org
 
M

Mike Brind [MVP]

Not really wanting to encourage ASP.NET questions and answers here (but
since it has been started), the default user on XP Pro is ASPNET, whereas
it's NETWORK SERVICE on Win2k3.

You can find various samples showing Access in use with ADO.NET code here:
www.mikesdotnetting.com. Feel free to post further Access and ASP.NET
related questions here: http://forums.asp.net/55.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top