By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,904 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,904 IT Pros & Developers. It's quick & easy.

Calling a Microsoft Access Module using ASP.NET

P: n/a

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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.