I am trying to convert my VS2003 project to VS2005 beta 2. The actual conversion has gone fine, but some code that was working fine under to old IDE is now giving me an exception when run under the VS2005 generated code.
The code is:
using (SqlConnection conn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=GestionNET00001;Data Source=localhost")
{
...
And the error I'm getting is:
{"The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception."}
Has anyone any idea why this is happening
TIA,
MartinH.

Problem converting VS2003 code to VS2005
Dipendra
kregger
Try also including the System.Data.SqlClient namespace
clayton h
Anyway, have you tried a simple declaration instead of using the using statement
i.e.
SqlConnection conn;
conn = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=GestionNET00001;Data Source=localhost");
Does it fail on either of those lines if it's written out like that
If not, then merge them together into the same statement and see if that works.
If it does, try putting them back into the using statement and see what happens...
Niraj Shah
Yes that was a typo, sorry, but in my code it was correct and compiled correctly.
I have since tried to declare and instantiate the connection without a connection string, but still have the same problem. I have also tried to eliminate the 'using' block, still the same.
There seems to be a problem at runtime, but I have checked the 'references' and Syatem.Data is included, I don't think I need anything else for SqlConnection.
Finally, when I installed VS2005 b2, the SqlConnection, SqlCommand and other family members were not installed on the tool pallete, I have to install them manuallly. Is this standard procedure for VS2005 If not this may be related to the problem I have.
TIA,
MartinH.
nblankton
This seems to be a bug in how the config file is being processed.
Private Sub InitConnection() Me.m_connection = New System.Data.SqlClient.SqlConnection Me.m_connection.ConnectionString = DnD.Settings.Default.DnDConnectionString End Sub
InstantKarma
It was 2 fold. First, I was using the Microsoft Enterprise Library for January 2005, and once I removed this from my project it worked fine. Maybe the June update will work okay, I will have to try it.
Secondly, I use Developer Express's XPO and had the 'trace' feature enabled (within the App.config file). Turning this option off also solved the problem.
I have tried each option individually and they both cause the problem to reappear.
HTH,
MartinH.