473,473 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Database issue

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.LastInd exOf("/")
+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.
PS: There will be line wrap issues in the above code and I have only
included that part of the If statement to the point of failure, the
rsCounter.update() etc. still has to be added in.

Thanks
BD
Jun 27 '08 #1
4 1260
First, I am not sure that a counter is best implemented in a database. There
are plenty of examples on the web of counters persisted in memory and spun
down and up as the application is started and stopped. You can also persist
hits to an XML file, if you would rather head that direction.

Second, even if you persist each hit to the database, I am not sure why you
are adding new rows. It is a single value updated over and over again,
right?

Third, why are you using old style ADO objects instead of ADO.NET objects.
There is really no need for this line:
Server.CreateObject("ADODB.Recordset")
other than familiarity with the old. ADO.NET will be faster and easier to
debug than a COM object, as you have full exposure of what is going on. When
you use an ADODB.Recordset, the COM errors are trapped and .NET exceptions
thrown, which obfuscates what is actually going on.

Finally, you are writing your ASP.NET like ASP, which is not the optimal way
to do something like this.

As for the error, what error are you recieving? One of the most common
errors comes from opening the Access database in Access while you are trying
to hit it with the web page. I forget the error number, but the error
message is completely unrelated to what is actually happening, in most
cases. You are probably not seeing this error anyway, as .NET is trapping it
and throwing its own exception.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"BD" <Ju****@nothome.netwrote in message
news:eW**************@TK2MSFTNGP04.phx.gbl...
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.LastInd exOf("/")
+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.
PS: There will be line wrap issues in the above code and I have only
included that part of the If statement to the point of failure, the
rsCounter.update() etc. still has to be added in.

Thanks
BD


Jun 27 '08 #2
BD
Thanks for the reply Cowboy.
First off, I'm very new to ASP.Net and to ASP in general. I'm used to doing
my page code in straight HTML using FrontPage 2003.
I really don't have any idea how to proceed with this and I'm just trying to
muddle my way through it. The reason for using the database was that there
are several pages that will be tracked in that table and the DB also has
another table that I want to implement later for tracking downloads of zip
and exe files which are available on the site.
The error is that the database is read only which I understand has to do
with folder permissions. I can probably solve that on IIS 6 which I use for
testing only. The pages finally end up on another server which is 2003 and
I have no way (AFAIK) of setting folder permissions there.
I'm open to any code that you think will do what I want but I warn you in
advance that this will be a "Hold my hand" operation.
Again, my gratitude for your help here.
BD

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:OQ**************@TK2MSFTNGP03.phx.gbl...
First, I am not sure that a counter is best implemented in a database.
There are plenty of examples on the web of counters persisted in memory
and spun down and up as the application is started and stopped. You can
also persist hits to an XML file, if you would rather head that direction.

Second, even if you persist each hit to the database, I am not sure why
you are adding new rows. It is a single value updated over and over
again, right?

Third, why are you using old style ADO objects instead of ADO.NET objects.
There is really no need for this line:
Server.CreateObject("ADODB.Recordset")
other than familiarity with the old. ADO.NET will be faster and easier to
debug than a COM object, as you have full exposure of what is going on.
When you use an ADODB.Recordset, the COM errors are trapped and .NET
exceptions thrown, which obfuscates what is actually going on.

Finally, you are writing your ASP.NET like ASP, which is not the optimal
way to do something like this.

As for the error, what error are you recieving? One of the most common
errors comes from opening the Access database in Access while you are
trying to hit it with the web page. I forget the error number, but the
error message is completely unrelated to what is actually happening, in
most cases. You are probably not seeing this error anyway, as .NET is
trapping it and throwing its own exception.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box! |
*************************************************

Jun 27 '08 #3
The read only can come from a couple of things:

1. Permissions on the file
2. Permissions on the folder
3. You have the file open while you are running your application

The last is unique to file type databases, like Access, and will only
require a bit of discipline on your part.

If you have an ISP that has a server type database, I would aim that
direction before using Access, personally. Many provide either SQL Express
or mySQL. You can download both for free, so there is no cost issue here.

That is a bit overkill for a simple page counter, however. I will post back
something shortly.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"BD" <Ju****@nothome.netwrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
Thanks for the reply Cowboy.
First off, I'm very new to ASP.Net and to ASP in general. I'm used to
doing my page code in straight HTML using FrontPage 2003.
I really don't have any idea how to proceed with this and I'm just trying
to muddle my way through it. The reason for using the database was that
there are several pages that will be tracked in that table and the DB also
has another table that I want to implement later for tracking downloads of
zip and exe files which are available on the site.
The error is that the database is read only which I understand has to do
with folder permissions. I can probably solve that on IIS 6 which I use
for testing only. The pages finally end up on another server which is
2003 and I have no way (AFAIK) of setting folder permissions there.
I'm open to any code that you think will do what I want but I warn you in
advance that this will be a "Hold my hand" operation.
Again, my gratitude for your help here.
BD

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:OQ**************@TK2MSFTNGP03.phx.gbl...
>First, I am not sure that a counter is best implemented in a database.
There are plenty of examples on the web of counters persisted in memory
and spun down and up as the application is started and stopped. You can
also persist hits to an XML file, if you would rather head that
direction.

Second, even if you persist each hit to the database, I am not sure why
you are adding new rows. It is a single value updated over and over
again, right?

Third, why are you using old style ADO objects instead of ADO.NET
objects. There is really no need for this line:
Server.CreateObject("ADODB.Recordset")
other than familiarity with the old. ADO.NET will be faster and easier to
debug than a COM object, as you have full exposure of what is going on.
When you use an ADODB.Recordset, the COM errors are trapped and .NET
exceptions thrown, which obfuscates what is actually going on.

Finally, you are writing your ASP.NET like ASP, which is not the optimal
way to do something like this.

As for the error, what error are you recieving? One of the most common
errors comes from opening the Access database in Access while you are
trying to hit it with the web page. I forget the error number, but the
error message is completely unrelated to what is actually happening, in
most cases. You are probably not seeing this error anyway, as .NET is
trapping it and throwing its own exception.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*********************************************** **
| Think outside the box! |
*********************************************** **


Jun 27 '08 #4
BD
Thanks again Cowboy. I'll be checking your blog. Really all I need it the
ability to track the info. Displaying it on the pages is not a requirement.
It's just so that I can open a private page and see what the stats are. I
don't really want to use the separate counter file pages for each page that
the user sees. I'm also looking at the possibility of tracking it with XML
or an INI file.
BD

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:Ot**************@TK2MSFTNGP06.phx.gbl...
Here is a zip file of a counter application. I did not have time to move
teh dataset creation and save routines to global.asax, so there is still
some work to be done. It is C#. I tried to do VB, but it takes more time
than I have for me to think in VB anymore. I apolgize up front. One of the
easiest ways to translate is publish the website, which compiles it, and
look at the code in Reflector (Lutz Roeder), a mandatory tool for .NET
devs, IMO.

Here are some things to note:
1. Open Counters.xml and see that only one of the two pages has a counter
2. Hit both pages. You can go back and forth and see how the counters
work - If they saved back to the XML file, you would also see that you can
quit the application. I am not sure when I will find more time, so you can
lookup Application_Start and counters and try yourself. It will not work
with pagePath, as it is a Uri, not a regular path. There is a routine for
getting application path in .NET. I just don't have it at the top of my
head.

The application is designed to add new pages. All you have to do to see
the counter is place it on a label or something. If you want a prettier
counter, I would create a user control that pulls images 1-10 and turn the
count into a string and read each character. Something like:

<!-- in page -->
<asp:Panel ID="HitCounterPanel" runat="Server"/>

//In Code
HitCounterPanel.Controls.Clear();
string hitsAsString = hits.ToString();
char[] hitsAsArray = hitsAsString.ToCharArray();

for(int i=0;i<hitsAsArray.Length;i++)
{
Image img = new Image();
img.ImageUrl = "images/" + hitsAsArray[i] + ".gif";
HitCounterPanel.Coutrols.Add(img);
}

I may have a typo in that. If I get time, I can show you how easy it can
be to use a database. I will likely do it on my blog so it has a wider
audience.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box! |
*************************************************
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:eM**************@TK2MSFTNGP06.phx.gbl...
>The read only can come from a couple of things:

1. Permissions on the file
2. Permissions on the folder
3. You have the file open while you are running your application

The last is unique to file type databases, like Access, and will only
require a bit of discipline on your part.

If you have an ISP that has a server type database, I would aim that
direction before using Access, personally. Many provide either SQL
Express
or mySQL. You can download both for free, so there is no cost issue here.

That is a bit overkill for a simple page counter, however. I will post
back
something shortly.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*********************************************** **
| Think outside the box!
|
*********************************************** **
"BD" <Ju****@nothome.netwrote in message
news:Om**************@TK2MSFTNGP05.phx.gbl...
>>Thanks for the reply Cowboy.
First off, I'm very new to ASP.Net and to ASP in general. I'm used to
doing my page code in straight HTML using FrontPage 2003.
I really don't have any idea how to proceed with this and I'm just
trying
to muddle my way through it. The reason for using the database was that
there are several pages that will be tracked in that table and the DB
also
has another table that I want to implement later for tracking downloads
of
zip and exe files which are available on the site.
The error is that the database is read only which I understand has to do
with folder permissions. I can probably solve that on IIS 6 which I use
for testing only. The pages finally end up on another server which is
2003 and I have no way (AFAIK) of setting folder permissions there.
I'm open to any code that you think will do what I want but I warn you
in
advance that this will be a "Hold my hand" operation.
Again, my gratitude for your help here.
BD

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote
in
message news:OQ**************@TK2MSFTNGP03.phx.gbl...
First, I am not sure that a counter is best implemented in a database.
There are plenty of examples on the web of counters persisted in memory
and spun down and up as the application is started and stopped. You can
also persist hits to an XML file, if you would rather head that
direction.

Second, even if you persist each hit to the database, I am not sure why
you are adding new rows. It is a single value updated over and over
again, right?

Third, why are you using old style ADO objects instead of ADO.NET
objects. There is really no need for this line:
Server.CreateObject("ADODB.Recordset")
other than familiarity with the old. ADO.NET will be faster and easier
to
debug than a COM object, as you have full exposure of what is going on.
When you use an ADODB.Recordset, the COM errors are trapped and .NET
exceptions thrown, which obfuscates what is actually going on.

Finally, you are writing your ASP.NET like ASP, which is not the
optimal
way to do something like this.

As for the error, what error are you recieving? One of the most common
errors comes from opening the Access database in Access while you are
trying to hit it with the web page. I forget the error number, but the
error message is completely unrelated to what is actually happening, in
most cases. You are probably not seeing this error anyway, as .NET is
trapping it and throwing its own exception.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*********************************************** **
| Think outside the box! |
*********************************************** **





Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I...
2
by: vrbala | last post by:
Hi All, I have a issue in federated database. I will explain the scenario I have a table T1 in database called offlinedb. It has one column F1 I have an another table T2 in database uatdb. I...
6
by: N. Graves | last post by:
Thank you for taking your time to read my question... please offer your knowledge it will be appreciated! I'm writing a ASP Web page to access a Access Database that has a Database Password set....
3
by: headware | last post by:
We're using an access database and are getting a lot of crashes when as little as 3 or so users try to write to the database at the same time. Typically it's the "operation must use updateable...
1
by: Larry Dooley | last post by:
Here's my issue. We've decided to replace a very critical (without it the business would lose lots of money) departmental reporting system with a built from scratch system based on .NET. The key...
12
by: mistral | last post by:
phpMyAdmin 2.6.2 problem: can no connects to mySQL database: each time shown error #1045 - Access denied for user 'username'@'192.168.1.2' (using password: YES) Is seems, this is most common...
9
by: Jerim79 | last post by:
I am no PHP programmer. At my current job I made it known that I was no PHP programmer during the interview. Still they have given me a script to write with the understanding that it will take me a...
17
by: darien.watkins | last post by:
Kindof a poll, kindof curiosity... What is your favorite python - database combination? I'm looking to make an app that has a local DB and a server side DB. I'm looking at python and sqlite...
1
by: vbace2 | last post by:
I have searched this forum, and the web, and I have not been able to find a solution to my issue. I may not have used the right search information to find the answer, but I found a lot of issues...
25
by: zmickle | last post by:
Excuse my noobness. I am managing an access database that is shared by 4 users. Management does not want to use any technologies outside of access for this application (no SQL Server, etc). I...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.