473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Calling a Microsoft Access Module using ASP.NET


I was wondering if anyone had any code samples on how to call functions
within a Microsoft Access module using ASP.NET. I found a posting on how
to do it with C#, but does anyone know how to do it using VB and
ASP.NET?

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #1
4 4812
On Mon, 22 Nov 2004 14:50:26 -0800, Matt Howard <mb*******@yahoo.com> wrote:

¤
¤ I was wondering if anyone had any code samples on how to call functions
¤ within a Microsoft Access module using ASP.NET. I found a posting on how
¤ to do it with C#, but does anyone know how to do it using VB and
¤ ASP.NET?
¤

See the following MS KB article:

How To Run Office Macros by Using Automation from Visual Basic .NET
http://support.microsoft.com/default...b;en-us;306682

Just an FYI, Microsoft does not support automation of the Office applications from non-interactive
processes such as web applications or services, as a result of threading issues.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #2
Paul,

Thanks for the reference. I followed the instructions on that web page
(including only the Access portion of the code). Here is the code that I
have so far:

****************
Imports Access = Microsoft.Office.Interop.Access

Public Class WebForm1
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim oAccess As Access.ApplicationClass

'Start Access and open the database.
oAccess = Server.CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase("c:\BizRulesProject\bi zrules.mdb",
False)

'Run the macros.
oAccess.Run("DoKbTest")
oAccess.Run("DoKbTestWithParameter", "Hello from VB .NET
Client")

'Clean-up: Quit Access without saving changes to the database.
oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSav eNone)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)
oAccess = Nothing

GC.Collect()
End Sub
End Class

****************

I am getting the error "System.UnauthorizedAccessException: Access is
denied." when I click on the button that executes the "Button1_Click"
function.

To try and fix this, I added the ASPNET user to my Inetpub directory and
made sure it was in all of the subfolders (i.e. "wwwroot"). I gave this
user read, write and execute permissions. I also added my local "IUSR"
account and gave the same permissions.

I re-run the web browser and I get the same "Unauthorized Access" error.

I am not exactly sure which user ASP.NET is using to run the
application. I assume it is the "ASP.NET Machine Account". I wanted to
add the IUSR account just to be on the safe side. DO I have the right
user? Am I adding the user to the appropriate folders (Inetpub and
below)?

HELP! I feel like I'm sooooooo close!

Matt

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #3
On Tue, 23 Nov 2004 10:19:50 -0800, Matt Howard <mb*******@yahoo.com> wrote:

¤ Paul,
¤
¤ Thanks for the reference. I followed the instructions on that web page
¤ (including only the Access portion of the code). Here is the code that I
¤ have so far:
¤
¤ ****************
¤ Imports Access = Microsoft.Office.Interop.Access
¤
¤ Public Class WebForm1
¤ Inherits System.Web.UI.Page
¤
¤ Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
¤ System.EventArgs) Handles MyBase.Load
¤ 'Put user code to initialize the page here
¤ End Sub
¤
¤ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
¤ System.EventArgs) Handles Button1.Click
¤
¤ Dim oAccess As Access.ApplicationClass
¤
¤ 'Start Access and open the database.
¤ oAccess = Server.CreateObject("Access.Application")
¤ oAccess.Visible = True
¤ oAccess.OpenCurrentDatabase("c:\BizRulesProject\bi zrules.mdb",
¤ False)
¤
¤ 'Run the macros.
¤ oAccess.Run("DoKbTest")
¤ oAccess.Run("DoKbTestWithParameter", "Hello from VB .NET
¤ Client")
¤
¤ 'Clean-up: Quit Access without saving changes to the database.
¤ oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSav eNone)
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)
¤ oAccess = Nothing
¤
¤ GC.Collect()
¤ End Sub
¤ End Class
¤
¤ ****************
¤
¤ I am getting the error "System.UnauthorizedAccessException: Access is
¤ denied." when I click on the button that executes the "Button1_Click"
¤ function.
¤
¤ To try and fix this, I added the ASPNET user to my Inetpub directory and
¤ made sure it was in all of the subfolders (i.e. "wwwroot"). I gave this
¤ user read, write and execute permissions. I also added my local "IUSR"
¤ account and gave the same permissions.
¤
¤ I re-run the web browser and I get the same "Unauthorized Access" error.
¤
¤ I am not exactly sure which user ASP.NET is using to run the
¤ application. I assume it is the "ASP.NET Machine Account". I wanted to
¤ add the IUSR account just to be on the safe side. DO I have the right
¤ user? Am I adding the user to the appropriate folders (Inetpub and
¤ below)?
¤
¤ HELP! I feel like I'm sooooooo close!
¤
¤ Matt

If you're not implementing impersonation then the ASPNET account is being used. You probably also
need to provide sufficient permissions to the folder where the Access database is located so that
the Jet database engine can create and delete the corresponding .LDB file.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 22 '05 #4

add a line to your web.config like follows:
<identity impersonate="true" userName="YourAdminUsr"
password="YourAdminPwd"/>
then you will be able to run office as COM in ASP.NET.

see also http://support.microsoft.com/default...b;EN-US;257757 for
more detail.

using office in web server maybe not a good idea.
best,
Eric


"Paul Clement" <Us***********************@swspectrum.com> ????
news:qt********************************@4ax.com...
On Tue, 23 Nov 2004 10:19:50 -0800, Matt Howard <mb*******@yahoo.com> wrote:
¤ Paul,
¤
¤ Thanks for the reference. I followed the instructions on that web page
¤ (including only the Access portion of the code). Here is the code that I
¤ have so far:
¤
¤ ****************
¤ Imports Access = Microsoft.Office.Interop.Access
¤
¤ Public Class WebForm1
¤ Inherits System.Web.UI.Page
¤
¤ Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
¤ System.EventArgs) Handles MyBase.Load
¤ 'Put user code to initialize the page here
¤ End Sub
¤
¤ Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
¤ System.EventArgs) Handles Button1.Click
¤
¤ Dim oAccess As Access.ApplicationClass
¤
¤ 'Start Access and open the database.
¤ oAccess = Server.CreateObject("Access.Application")
¤ oAccess.Visible = True
¤ oAccess.OpenCurrentDatabase("c:\BizRulesProject\bi zrules.mdb",
¤ False)
¤
¤ 'Run the macros.
¤ oAccess.Run("DoKbTest")
¤ oAccess.Run("DoKbTestWithParameter", "Hello from VB .NET
¤ Client")
¤
¤ 'Clean-up: Quit Access without saving changes to the database.
¤ oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSav eNone)
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject(oAccess)
¤ oAccess = Nothing
¤
¤ GC.Collect()
¤ End Sub
¤ End Class
¤
¤ ****************
¤
¤ I am getting the error "System.UnauthorizedAccessException: Access is
¤ denied." when I click on the button that executes the "Button1_Click"
¤ function.
¤
¤ To try and fix this, I added the ASPNET user to my Inetpub directory and
¤ made sure it was in all of the subfolders (i.e. "wwwroot"). I gave this
¤ user read, write and execute permissions. I also added my local "IUSR"
¤ account and gave the same permissions.
¤
¤ I re-run the web browser and I get the same "Unauthorized Access" error.
¤
¤ I am not exactly sure which user ASP.NET is using to run the
¤ application. I assume it is the "ASP.NET Machine Account". I wanted to
¤ add the IUSR account just to be on the safe side. DO I have the right
¤ user? Am I adding the user to the appropriate folders (Inetpub and
¤ below)?
¤
¤ HELP! I feel like I'm sooooooo close!
¤
¤ Matt

If you're not implementing impersonation then the ASPNET account is being used. You probably also need to provide sufficient permissions to the folder where the Access database is located so that the Jet database engine can create and delete the corresponding .LDB file.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 22 '05 #5

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

Similar topics

1
by: Andrew Wilkinson | last post by:
Hi, First off I know that in almost all cases this would be a terrible thing to do, but this is an unusual case where this makes sense. Basically I have a procedure where you pass a string...
2
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience,...
7
by: Doug Rosser | last post by:
I'm writing a fairly complicated test framework and keeping configuration data inside ini files that are parsed at runtime by the ConfigParser module. For example, there would be a section...
4
by: Matt Howard | last post by:
I was wondering if anyone had any code samples on how to call functions within a Microsoft Access module using ASP.NET. I found a posting on how to do it with C#, but does anyone know how to do it...
5
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without...
17
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access...
5
by: Richard MSL | last post by:
I am porting my application from .NET 1.1 to 2.0. It worked fine in 1.1, but will not compile in 2.0. I have this function in a c++ file: namespace CPPBack { public __gc class CPPClass{...
9
by: =?Utf-8?B?Wm9vZG9y?= | last post by:
I have a web service, written in C#, that calls a managed C++ library that itself calls a third-party unmanaged C++ library (which is its only purpose - to allow me to call some unmanaged C++ from...
4
by: MLH | last post by:
I have the following saved UNION query named qryPeople2NameInNPaperAd: SELECT & " " & & " " & & " " & & ", " & & " " & AS Item, tblVehicleJobs.VehicleJobID FROM tblVehicleJobs INNER...
3
by: Alain Bourgeois | last post by:
Dear all, I have an asp module connecting to a MS-access database. I have a vb function MKDate(date, time) in a vba module of this database. I would like to query : SELECT MKDATE(col1,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.