缺少实体框架连接字符串后Visual Studio 2012堆栈溢出
本文关键字:Visual Studio 2012堆 栈溢出 字符串 实体 框架 连接 | 更新日期: 2023-09-27 18:00:44
我在VS2012中使用win2k8 r2 64位上的更新1。
在一个简单的类库应用程序中,我执行Add>NewItem>ADO。NET实体数据模型
我在网络上选择一个SQL Server,然后选择数据库并添加一个表。该表被添加,我可以在代码中作为类名访问它。
问题是:当我使用后端数据库做任何事情时,使用我库的应用程序会崩溃,并出现stackerflow错误(无一例外)。例如,这将崩溃:var logs =_db_context.LOGs.ToList();
有什么想法吗?
编辑:同样的项目在VS2010中在同一台机器上运行。这是在我升级到VS2012时才开始发生的,VS2012也升级了实体框架。还值得一提的是,如果我删除访问数据库的代码,应用程序运行得很好。此外,删除并重新添加.edmx没有帮助,清理/重新构建或重新启动VS.也没有帮助
EDIT2:调试后,我注意到当到达行LogServerEntities context = new LogServerEntities()
时,我尝试从"Locals"扩展上下文变量VS结束调试,说Managed (v4.0.30319)' has exited with code -2146233082 (0x80131506).
类库实际上是一个自定义跟踪侦听器,看起来如下所示。当我在构造函数中注释FirstChanceHandler时,异常实际上进入了控制台输出:未能加载程序集引用(System.Management.Automation)。我并不真的需要那个程序集,只是简单地删除了它,stackoverflow错误(我猜这是一个错误)就消失了。
public Listener()
{
AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler;
}
public void FirstChanceHandler(object source, FirstChanceExceptionEventArgs e)
{
WriteException(e.Exception);
}
public void WriteException(Exception e)
{
string app_identity = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name;
string server_name = System.Environment.MachineName;
using (LogServerEntities context = new LogServerEntities())
{
LOG log = new LOG();
log.DATE = DateTime.Now;
log.THREAD = Thread.CurrentThread.Name;
log.MESSAGE = e.Message;
log.LOGGER = string.Format("{0} {1}", app_identity, server_name);
log.LEVEL = Level.Exception.ToString();
log.EXCEPTION = e.GetType().FullName;
var web_exception = e as WebException;
if (web_exception != null)
{
if (web_exception.Status == WebExceptionStatus.ProtocolError)
{
var response = web_exception.Response as HttpWebResponse;
if (response != null)
log.HTTP_RESPONSE_CODE = ((int)response.StatusCode).ToString();
else
log.HTTP_STATUS = web_exception.Status.ToString();
}
else
{
log.HTTP_STATUS = web_exception.Status.ToString();
}
}
context.LOGs.Add(log);
context.SaveChanges();
}
}