Calling a Microsoft Access Module using ASP.NET

  • Thread starter Thread starter Matt Howard
  • Start date Start date
M

Matt Howard

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
 
¤
¤ 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.aspx?scid=kb;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 ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
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\bizrules.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.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject(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
 
¤ 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\bizrules.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.acQuitSaveNone)
¤ System.Runtime.InteropServices.Marshal.ReleaseComObject(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 ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top