SqlConnection with VS2005 and NET2 problem.

  • Thread starter Thread starter Martin Hart Turner
  • Start date Start date
M

Martin Hart Turner

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=True;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.
 
Miha:

I believe all the required references are present. The System.Data
reference is there and I think this is all that is required for
SqlConnection.

I have made a simple test project and it works fine. I then checked the
references and made sure all of these were present in the main project.
Unfortunately the problem persists.

Thanks,
Martin.

Miha Markic [MVP C#] escribió:
 
If a console application like
public static void Main() { (new
System.Data.SqlClient.SqlConnection()).Dispose(); }
is throwing a type initializer exception then it sounds like the performance
counters where not properly registered during setup.
 
Mark:

Yes that does sound like a definite possibility, I'll do a reinstall and
drop back here when I have the results.

Thanks,
MartinH.

Mark Ashton escribió:
 
hey it may be the problem with app.config settings.

u hv to code like this



<appSettings>

<add key ="ConnectionString" value="Data Source=server name;Initial
Catalog=db name;User ID= sa;Password= sa"/>

</appSettings>



if u code this wrongly ,typeintializer error w'll throw.

Also if the key name is used different from app.config also exception will
throw.
 
I am not sure if this will work for you, but here are my 2cents...



My coworker got the same error when he was trying to connect to SQL Server
2005. I uninstalled SQL Server 2005 and installed it again, but that didn't
fix it. I uninstalled .Net 2.0 Framework along with SQL Server 2005 and
installed it again, and that fixed it.



I think a dll file in the framework was corrupt and that was the reason it
threw the error in my case...
 
Back
Top