猿问

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.

  在程序中,使用Microsoft.SqlServer.Management.Common空间下的ServerConnection类时,在创建它的实例时出现了如标题所示的错误。查找了一些资料,有人说是config文件配置有问题。在我的config文件中有如下配置:

 <startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<requiredruntime version="v4.0.30319" />
</startup>
<configSection>
   <Section name="MM" type="....."/>
</configSection>
<MM>
<any name="ss"/>
</MM>

如果把这段配置去掉就可以正确创建ServerConnection对象。或者把configSection的配置却掉也能正常运行。请问这是什么原因造成的?

我添加上面的配置原因是用于解决“mixed mode"异常的。因为在使用smo的事务管理时,当调用ServerConnection.BegionTransaction()方法时,总是出现异常”Mixed mode assembly........"。到底smo的事务管理是如何使用的?

参考资料:http://objectmix.com/csharp/119948-sqlclient-system-typeinitializationexception-real-head-scratcher.html

阿波罗的战车
浏览 1317回答 2
2回答

慕标5832272

对英语无爱........没看错的话你的configSection节点下面,那少很多属性参数的样子?服务器,数据库,用户名,登录密码..........请原谅我的无知

陪伴而非守候

  将工程.net版本下降到3.5可以用了!
随时随地看视频慕课网APP
我要回答