VB.net Error When Trying To Connect To Access Database With OpenCurrentDatabase in...












0















I am trying to get a legacy system to work in a new environment. The legacy system consists of a VB.net application that connects to an Access database. My new environment consists of Visual Studio 2017 and Access 365.



When I try to run the application, I get an error message that reads,




System.AccessViolationException: 'Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt.'




I have created a new VB.net application and Access database from scratch and am able to recreate the error. The VB code is below.



Imports Microsoft.Office.Interop

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oAccess As Access.Application
oAccess = New Access.Application
oAccess.OpenCurrentDatabase("C:MyDatabaseNewAccessDatabase.accdb")
End Sub
End Class


The error occurs on the last line of the method with the call to OpenCurrentDatabase.



I have read on other forums that this error can be fixed by clicking on Visual Studio's Build menu, opening the Configuration Manager screen, and changing the Platform setting. I have done that, but with no luck. However, I am sometimes able to get a different error message (on the same line of code) that reads,




System.InvalidCastException: 'Unable to cast COM object of type
'Microsoft.Office.Interop.Access.ApplicationClass' to interface type
'Microsoft.Office.Interop.Access._Application'. This operation failed
because the QueryInterface call on the COM component for the interface
with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the
following error: Error loading type library/DLL. (Exception from
HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'




However, resolving this error hasn't been any easier than resolving the first one.



If someone could help me to resolve this error, I would really appreciate it. I didn't think that one method call to OpenCurrentDatabase could cause so much difficulty, but it is!










share|improve this question




















  • 1





    do you have access installed on your computer? Also, force you VS project to x32 bits - it should (and in general has to) match the bit size of office you are using.

    – Albert D. Kallal
    Nov 23 '18 at 22:54











  • Thanks, Albert. Yes, I have Access installed on my computer, and I have forced my VS project to x32 bits.

    – MrMike
    Dec 19 '18 at 21:44
















0















I am trying to get a legacy system to work in a new environment. The legacy system consists of a VB.net application that connects to an Access database. My new environment consists of Visual Studio 2017 and Access 365.



When I try to run the application, I get an error message that reads,




System.AccessViolationException: 'Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt.'




I have created a new VB.net application and Access database from scratch and am able to recreate the error. The VB code is below.



Imports Microsoft.Office.Interop

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oAccess As Access.Application
oAccess = New Access.Application
oAccess.OpenCurrentDatabase("C:MyDatabaseNewAccessDatabase.accdb")
End Sub
End Class


The error occurs on the last line of the method with the call to OpenCurrentDatabase.



I have read on other forums that this error can be fixed by clicking on Visual Studio's Build menu, opening the Configuration Manager screen, and changing the Platform setting. I have done that, but with no luck. However, I am sometimes able to get a different error message (on the same line of code) that reads,




System.InvalidCastException: 'Unable to cast COM object of type
'Microsoft.Office.Interop.Access.ApplicationClass' to interface type
'Microsoft.Office.Interop.Access._Application'. This operation failed
because the QueryInterface call on the COM component for the interface
with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the
following error: Error loading type library/DLL. (Exception from
HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'




However, resolving this error hasn't been any easier than resolving the first one.



If someone could help me to resolve this error, I would really appreciate it. I didn't think that one method call to OpenCurrentDatabase could cause so much difficulty, but it is!










share|improve this question




















  • 1





    do you have access installed on your computer? Also, force you VS project to x32 bits - it should (and in general has to) match the bit size of office you are using.

    – Albert D. Kallal
    Nov 23 '18 at 22:54











  • Thanks, Albert. Yes, I have Access installed on my computer, and I have forced my VS project to x32 bits.

    – MrMike
    Dec 19 '18 at 21:44














0












0








0








I am trying to get a legacy system to work in a new environment. The legacy system consists of a VB.net application that connects to an Access database. My new environment consists of Visual Studio 2017 and Access 365.



When I try to run the application, I get an error message that reads,




System.AccessViolationException: 'Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt.'




I have created a new VB.net application and Access database from scratch and am able to recreate the error. The VB code is below.



Imports Microsoft.Office.Interop

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oAccess As Access.Application
oAccess = New Access.Application
oAccess.OpenCurrentDatabase("C:MyDatabaseNewAccessDatabase.accdb")
End Sub
End Class


The error occurs on the last line of the method with the call to OpenCurrentDatabase.



I have read on other forums that this error can be fixed by clicking on Visual Studio's Build menu, opening the Configuration Manager screen, and changing the Platform setting. I have done that, but with no luck. However, I am sometimes able to get a different error message (on the same line of code) that reads,




System.InvalidCastException: 'Unable to cast COM object of type
'Microsoft.Office.Interop.Access.ApplicationClass' to interface type
'Microsoft.Office.Interop.Access._Application'. This operation failed
because the QueryInterface call on the COM component for the interface
with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the
following error: Error loading type library/DLL. (Exception from
HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'




However, resolving this error hasn't been any easier than resolving the first one.



If someone could help me to resolve this error, I would really appreciate it. I didn't think that one method call to OpenCurrentDatabase could cause so much difficulty, but it is!










share|improve this question
















I am trying to get a legacy system to work in a new environment. The legacy system consists of a VB.net application that connects to an Access database. My new environment consists of Visual Studio 2017 and Access 365.



When I try to run the application, I get an error message that reads,




System.AccessViolationException: 'Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt.'




I have created a new VB.net application and Access database from scratch and am able to recreate the error. The VB code is below.



Imports Microsoft.Office.Interop

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oAccess As Access.Application
oAccess = New Access.Application
oAccess.OpenCurrentDatabase("C:MyDatabaseNewAccessDatabase.accdb")
End Sub
End Class


The error occurs on the last line of the method with the call to OpenCurrentDatabase.



I have read on other forums that this error can be fixed by clicking on Visual Studio's Build menu, opening the Configuration Manager screen, and changing the Platform setting. I have done that, but with no luck. However, I am sometimes able to get a different error message (on the same line of code) that reads,




System.InvalidCastException: 'Unable to cast COM object of type
'Microsoft.Office.Interop.Access.ApplicationClass' to interface type
'Microsoft.Office.Interop.Access._Application'. This operation failed
because the QueryInterface call on the COM component for the interface
with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the
following error: Error loading type library/DLL. (Exception from
HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'




However, resolving this error hasn't been any easier than resolving the first one.



If someone could help me to resolve this error, I would really appreciate it. I didn't think that one method call to OpenCurrentDatabase could cause so much difficulty, but it is!







vb.net ms-access office365






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 21:40







MrMike

















asked Nov 23 '18 at 21:24









MrMikeMrMike

284




284








  • 1





    do you have access installed on your computer? Also, force you VS project to x32 bits - it should (and in general has to) match the bit size of office you are using.

    – Albert D. Kallal
    Nov 23 '18 at 22:54











  • Thanks, Albert. Yes, I have Access installed on my computer, and I have forced my VS project to x32 bits.

    – MrMike
    Dec 19 '18 at 21:44














  • 1





    do you have access installed on your computer? Also, force you VS project to x32 bits - it should (and in general has to) match the bit size of office you are using.

    – Albert D. Kallal
    Nov 23 '18 at 22:54











  • Thanks, Albert. Yes, I have Access installed on my computer, and I have forced my VS project to x32 bits.

    – MrMike
    Dec 19 '18 at 21:44








1




1





do you have access installed on your computer? Also, force you VS project to x32 bits - it should (and in general has to) match the bit size of office you are using.

– Albert D. Kallal
Nov 23 '18 at 22:54





do you have access installed on your computer? Also, force you VS project to x32 bits - it should (and in general has to) match the bit size of office you are using.

– Albert D. Kallal
Nov 23 '18 at 22:54













Thanks, Albert. Yes, I have Access installed on my computer, and I have forced my VS project to x32 bits.

– MrMike
Dec 19 '18 at 21:44





Thanks, Albert. Yes, I have Access installed on my computer, and I have forced my VS project to x32 bits.

– MrMike
Dec 19 '18 at 21:44












1 Answer
1






active

oldest

votes


















2














It seems I had to do two things to resolve this issue. First, I repaired my installation of Office (by navigating to Control Panel, Programs and Features, selecting "Microsoft Office 365 ProPlus - en-us" from the list of programs, right-clicking and selecting Change, accepting the "Quick Repair" default radio button, and then clicking the Repair button). Second, I ran the "Microsoft Access database engine 2010 (English) Setup", which can be downloaded from this location: https://www.microsoft.com/en-ca/download/details.aspx?id=13255. I ran the AccessDatabaseEngine_2010.exe executable, accepted all of the default options, and then clicked the Install button. Once these two steps were completed, the error message stopped happening, and my code was able to use the Access database.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453075%2fvb-net-error-when-trying-to-connect-to-access-database-with-opencurrentdatabase%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    It seems I had to do two things to resolve this issue. First, I repaired my installation of Office (by navigating to Control Panel, Programs and Features, selecting "Microsoft Office 365 ProPlus - en-us" from the list of programs, right-clicking and selecting Change, accepting the "Quick Repair" default radio button, and then clicking the Repair button). Second, I ran the "Microsoft Access database engine 2010 (English) Setup", which can be downloaded from this location: https://www.microsoft.com/en-ca/download/details.aspx?id=13255. I ran the AccessDatabaseEngine_2010.exe executable, accepted all of the default options, and then clicked the Install button. Once these two steps were completed, the error message stopped happening, and my code was able to use the Access database.






    share|improve this answer




























      2














      It seems I had to do two things to resolve this issue. First, I repaired my installation of Office (by navigating to Control Panel, Programs and Features, selecting "Microsoft Office 365 ProPlus - en-us" from the list of programs, right-clicking and selecting Change, accepting the "Quick Repair" default radio button, and then clicking the Repair button). Second, I ran the "Microsoft Access database engine 2010 (English) Setup", which can be downloaded from this location: https://www.microsoft.com/en-ca/download/details.aspx?id=13255. I ran the AccessDatabaseEngine_2010.exe executable, accepted all of the default options, and then clicked the Install button. Once these two steps were completed, the error message stopped happening, and my code was able to use the Access database.






      share|improve this answer


























        2












        2








        2







        It seems I had to do two things to resolve this issue. First, I repaired my installation of Office (by navigating to Control Panel, Programs and Features, selecting "Microsoft Office 365 ProPlus - en-us" from the list of programs, right-clicking and selecting Change, accepting the "Quick Repair" default radio button, and then clicking the Repair button). Second, I ran the "Microsoft Access database engine 2010 (English) Setup", which can be downloaded from this location: https://www.microsoft.com/en-ca/download/details.aspx?id=13255. I ran the AccessDatabaseEngine_2010.exe executable, accepted all of the default options, and then clicked the Install button. Once these two steps were completed, the error message stopped happening, and my code was able to use the Access database.






        share|improve this answer













        It seems I had to do two things to resolve this issue. First, I repaired my installation of Office (by navigating to Control Panel, Programs and Features, selecting "Microsoft Office 365 ProPlus - en-us" from the list of programs, right-clicking and selecting Change, accepting the "Quick Repair" default radio button, and then clicking the Repair button). Second, I ran the "Microsoft Access database engine 2010 (English) Setup", which can be downloaded from this location: https://www.microsoft.com/en-ca/download/details.aspx?id=13255. I ran the AccessDatabaseEngine_2010.exe executable, accepted all of the default options, and then clicked the Install button. Once these two steps were completed, the error message stopped happening, and my code was able to use the Access database.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 19 '18 at 21:45









        MrMikeMrMike

        284




        284
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453075%2fvb-net-error-when-trying-to-connect-to-access-database-with-opencurrentdatabase%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin