[英]type initializer for System.Data.SqlClient threw an exception
This actually worked before but now, not. 这实际上在以前但现在没有奏效。
string sqlConnString ="Server=server1;Database=Production;Trusted_Connection=true;User ID=User;Password=pwd";
try {
conn = new SqlConnection(sqlConnString );
And I get the exception. 我得到了例外。 (I know the connection string should be in app.config but that didn't work, either.)
(我知道连接字符串应该在app.config中,但这也不起作用。)
This most likely means that there is an error in your app.config file, eg badly formed XML or unexpected elements. 这很可能意味着您的app.config文件中存在错误,例如XML格式错误或意外的元素。 The error happens because the static fields inside SqlConnection read from app.config to determine trace detail level as described here: http://msdn.microsoft.com/en-us/library/ms254503.aspx
发生错误是因为SqlConnection内的静态字段从app.config中读取,以确定跟踪详细信息级别,如下所述: http : //msdn.microsoft.com/zh-cn/library/ms254503.aspx
(this question is a duplicate of Exception: type initializer for 'system.data.sqlclient.sqlconnection'? ) (这个问题是Exception的重复:'system.data.sqlclient.sqlconnection'的类型初始化器? )
删除可信和连接之间的下划线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.