Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    4

    Exclamation Unanswered: Type Initializer threw exception - PsqlFactory

    I have developed my first .NET Widows Form application using VS 2005 C#, Pervasive 10.0 and the 3.0 .NET provider. The application runs fine on my development machine. When I deployed it to another machine (XP, Vista, or Server 2000), I immediately get:
    "The type initializer for 'MyApp.Utilities' threw exception."

    After some investigation and insertion of MessageBoxes, I determined it was taking place during the "static constructor" for the Utilities class that contained the line:
    static PsqlFactory Factory = (PsqlFactory)DbProviderFactories.GetFactory("Perva sive.Data.SqlClient");

    I was using
    conn = (PsqlConnection)Factory.CreateConnection()
    later to create connections. (This is the code in the Pervasive docummentation.)

    By eliminating the PsqlFactory and using
    conn = new PsqlConnection();
    the application is now deployable for testing on other machines.

    My questions are:
    - Am I loosing any capabilities by not using PsqlFactory?
    - Is there another way I should code this to use PsqlFactory?

  2. #2
    Join Date
    Dec 2001
    Posts
    1,109
    Provided Answers: 4
    I don't think you're losing any capabilities other than some database independence.
    To use the PsqlFactory, you need to make sure there is an entry in the dbProviderFactories section of the machine.config for the Pervasive.Data.SqlClient. It's added when the ADO.NET SDK is installed.
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    http://www.mirtheil.com
    I do not answer questions by email. Please post on the forum.

  3. #3
    Join Date
    Jul 2009
    Posts
    4
    When you say:
    Quote Originally Posted by mirtheil
    I don't think you're losing any capabilities other than some database independence.
    what do you mean by database independence? Is it new versions of Pervasive or or other DBMSs?

    Thanks for the machine.config info.

  4. #4
    Join Date
    Dec 2001
    Posts
    1,109
    Provided Answers: 4
    Actually it's either. Using PsqlFactory you can run your app against the 3.0 or 3.2 provider. Also by using the ProviderFactory, you can abstract the connection object to a DbConnection object rather than a PsqlConnection and use other providers (SQL Server, MySql,etc).
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    http://www.mirtheil.com
    I do not answer questions by email. Please post on the forum.

Posting Permissions

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