Results 1 to 7 of 7

Thread: type initializer exception on opening Foxpro database with DAO

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Unhappy type initializer exception on opening Foxpro database with DAO

    Greetings - I am trying to convert a VB6 program to VB2008

    Opening the project in VB2008 took me through a conversion wizard, and converted the following vb6 code...
    Set dbCompany = OpenDatabase(strDatabase, dbDriverComplete, False, "FoxPro 2.6")
    to VB2008 code...
    Dim dbCompany As DAO.Database
    dbCompany = DAODBEngine_definst.OpenDatabase(strDatabase, DAO.DriverPromptEnum.dbDriverComplete, False, "FoxPro 2.6")

    This compiles and runs on my pc.

    My problem is that it doesnt run when transferred to a different pc - I get the following error as soon as I try and run it...
    "The type initializer for VisiHH_ImportJobEstimates.UpgradeSupport threw an exception"
    (I know it is this line because the program starts if I comment out this line)

    Does the new pc require something that it does not have?
    I did a build, and copied all files to the new pc from my obj\release directory.
    I even tried did Publish and copied over my publish directory and ran setup (though its just one program)

    Alternatively - is there some other way that I should be connecting to the foxpro database?

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: type initializer exception on opening Foxpro database with DAO

    Ideally you would get rid of all the DAO code and use ADO.NET instead. Failing that, without having done anything similar, we'd need to know more details about the exception.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Re: type initializer exception on opening Foxpro database with DAO

    Unfortuantely the error givers no other details....gets to the dbCompany = .... and triggers the error catcher
    Err.Description = "The type initializer for VisiHH_ImportJobEstimates.UpgradeSupport threw an exception"
    (Note: the program is called VisiHH_ImportJobEstimates.exe ... VB2008 has created other files in the Release directory, but no ".UpgradeSupport")

    If ADO is considered superior or best practice then I am happy to try that.
    Do I need to include anything in my project, or will it recogise the ADO types?
    Can you please incude some sample code of how to define a database container and then open tables. ie replacement for...
    Dim dbCompany As DAO.Database
    Dim RsInventory As DAO.Recordset
    dbCompany = DAODBEngine_definst.OpenDatabase(strDatabase, DAO.DriverPromptEnum.dbDriverComplete, False, "FoxPro 2.6")
    RsInventory = dbCompany.OpenRecordset("Inventory")

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: type initializer exception on opening Foxpro database with DAO

    Quote Originally Posted by Anthonynz View Post
    Unfortuantely the error givers no other details
    I very much doubt that. If there's an exception then there's a stack trace and quite possibly an inner exception. Is the Exception Assistant window being displayed? If so then click the View Details link, which should be the logical first step anyway. If not then you can add your own exception handler and view the exception that way, e.g.
    Code:
    Try
        'your code here
    Catch ex As Exception
        MessageBox.Show(ex.ToString())
    End Try

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Re: type initializer exception on opening Foxpro database with DAO

    Ahhh - it is because I have an "On Error goto ..." that I get to see only the value of Err.Description
    Remove that and I get a different screen that shows the following
    System.TypeInitializationException: The type initializer for 'VisiHH_ImportJobEstimates.UpgradeSupport' threw an exception. ---> System.Runtime.InteropServices.COMException (0x80040112): Creating an instance of the COM component with CLSID {00000010-0000-0010-8000-00AA006D2EA4} from the IClassFactory failed due to the following error: 80040112.
    at VisiHH_ImportJobEstimates.UpgradeSupport..cctor() in C:\Visual Studio\Vision\VisiHH_ImportJobEstimate\UpgradeSupport.vb:line 2
    --- End of inner exception stack trace ---
    at VisiHH_ImportJobEstimates.VisiHH_ImportJobEstimates.VisiHH_ImportJobEstimates_Load(Object eventSender, EventArgs eventArgs) in C:\Visual Studio\Vision\VisiHH_ImportJobEstimate\VisiHH_ImportJobEstimates.vb:line 85
    at System.Windows.Forms.Form.OnLoad(EventArgs e)
    at System.Windows.Forms.Form.OnCreateControl()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.WmShowWindow(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmShowWindow(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4234 (VistaSP2GDR.050727-4200)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    VisiHH_ImportJobEstimates
    Assembly Version: 1.0.4976.34166
    Win32 Version: 1.0.4976.34166
    CodeBase: file:///V:/VISION/Utilities/VisiHH_ImportJobEstimates/VisiHH_ImportJobEstimates.exe
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4236 (VistaSP2GDR.050727-4200)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4235 (VistaSP2GDR.050727-4200)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4235 (VistaSP2GDR.050727-4200)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.4016 (NetFxQFE.050727-4000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4016 (NetFxQFE.050727-4000)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    Interop.DAO
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.0.0
    CodeBase: file:///V:/VISION/Utilities/VisiHH_ImportJobEstimates/Interop.DAO.DLL
    ----------------------------------------

    And I have found C:\Visual Studio\Vision\VisiHH_ImportJobEstimate\UpgradeSupport - it consists solely of
    Module UpgradeSupport
    Friend DAODBEngine_definst As New DAO.DBEngine
    End Module

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Re: type initializer exception on opening Foxpro database with DAO

    I note that my /bin contains Interop.DAO.dll which I have simply copied over to the second computer along with the rest of the /bin
    Perhaps I have to register it - presumably after copying it to c:\windows\system32 ?

    I have tried that - but the registration does not succeed - says "was loaded but the entry-point DllRegisterServer was not found"
    Re-trying via right click on cmd and selecting run as Administrator gave the same result.....any idea if this needs to be registered?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: type initializer exception on opening Foxpro database with DAO

    That Interop DLL is a .NET assembly, which don't get registered. It's the bridge between your .NET app and the DAO COM component, which is what gets registered. Is DAO already installed on a Windows machine or does it get installed with VB6? I don't know as I've never used it but, if it gets installed with VB6 and you don't have VB6 installed on that other machine, that would explain the issue.

    Is converting your data access code to ADO.NET feasible, because that would get rid of this issue as well as make maintaining and extending your app much easier.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width