Saturday, February 25, 2012

Problem converting VS2003 code to VS2005

Hi:

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.

You've got invalid parenthesis in that code sample you know?

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...|||

plenderj wrote:

You've got invalid parenthesis in that code sample you know?


Yes that was a typo, sorry, but in my code it was correct and compiled correctly.

plenderj wrote:

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?


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.|||I had a problem with VS2005 not automatically including the System.data namespace references for me to use and had to manually add it to the project properties.

Try also including the System.Data.SqlClient namespace|||Just for the record, I have found the solution to the afore mentioned problem.
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.|||I am having the same issue. The designer generated code is throwing the same error from the InitConnection function of one of my datasets. This only happens when I have a listener configured in the app.config file. If I comment out the Systems.Diagnotics section of the config file, I no longer get the error. The highlighted line below is throwing the error.

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

|||It's not a bug -- the confusing thing was where the error was thrown. Drilling into the exception made it clear that I had a typo in the diagnostics section of the config file.

No comments:

Post a Comment