Click here to Skip to main content
15,569,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got this error from my window service application

the type initializer for System.Data.SqlClient.SqlConnection threw an exception.


The following is the code:
Sqlconnection objconn = new SqlConnection("Data Source=Server1;Initial Catalog=Personel;Integrated Security=True");

I am not using the app.config. I tried a different way but still failed.

Regards
Posted
Updated 1-Mar-11 2:30am
v2

I realize you stated that you're not using the app.config, but try this:

If your app.config has a CustomConfiguration section, comment it out.
 
Share this answer
 
v2
There are lots od threads on internet discussing he same. Have a look at these two for now:
Changes in the SqlConnection class (.NET 2.0) [^]
Similar issue discussed at length[^]

It might be because of some unwanted tag in your app.config or your machine.config might have got corrupted. Looking deeper into the inner exception would surely help.
 
Share this answer
 
Thanks for the input. I deleted the app.config becuase it was corrupt. When I tried to view the properties of the config it gave me an error message.
I added a new one, add my values, deploy to production server, then it works.

Thanks for input.
:laugh:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900