If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Pervasive.SQL > Type Initializer threw exception - PsqlFactory

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-09, 14:29
pstymfal pstymfal is offline
Registered User
 
Join Date: Jul 2009
Posts: 4
Exclamation 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?
Reply With Quote
  #2 (permalink)  
Old 07-01-09, 14:49
mirtheil mirtheil is online now
Registered User
 
Join Date: Dec 2001
Posts: 1,015
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.
Reply With Quote
  #3 (permalink)  
Old 07-01-09, 15:15
pstymfal pstymfal is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 07-01-09, 16:24
mirtheil mirtheil is online now
Registered User
 
Join Date: Dec 2001
Posts: 1,015
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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On