简体   繁体   English

OleDB连接仅在调试时有效

[英]OleDB connection only working when debugging

I have a C# application that connects to a named SQL Express instance on the local machine using OleDBConnection: 我有一个C#应用程序,使用OleDBConnection连接到本地计算机上的命名SQL Express实例:

_connection = new OleDbConnection(_strConn);
_connection.Open();

_strConn is something like this: "Provider=sqloledb;Data Source=.\NAMEDINSTANCE;Initial Catalog=dbname;User Id=sa;Password=password;"

If I debug the application, the connection works fine. 如果我调试应用程序,连接工作正常。 If I run the application from Windows Explorer (the same debug compilation), I get an " OleDBException: Login timeout expired " in the Open() line after 30 seconds. 如果我从Windows资源管理器运行应用程序(相同的调试编译),30秒后我在Open()行中收到“ OleDBException:Login timeout expired ”。 The strange thing is the exception happens even if I attach the debugger to the exe. 奇怪的是,即使我将调试器附加到exe,也会发生异常。 I can see that the connection string is correct and everything seems fine. 我可以看到连接字符串是正确的,一切似乎都很好。 I can't fine any extra information in the SQL Express error log or SQL Activity Monitor either. 我不能在SQL Express错误日志或SQL活动监视器中使用任何额外信息。

If it helps, here is the exception: 如果它有帮助,这是例外:

    System.Data.OleDb.OleDbException: Login timeout expired
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()

I imagine that find the issue with the information I give here might be difficult, but I don't know where else to look or what other tests to do, so any ideas on what it could be or what test I could do to find out will be really appreciated. 我想,找到我在这里提供的信息的问题可能很难,但我不知道在哪里可以查看或者其他测试要做什么,所以任何关于它可能是什么的想法或者我可以做什么测试来找出将非常感激。

I fixed it. 我修好了它。 Unfortunately I don't really know how: I deleted the output folder, reset some project references, reconfigured several things on SQL Express, restarted the machine, etc. At some point, it started working fine again. 不幸的是我真的不知道如何:我删除了输出文件夹,重置了一些项目引用,在SQL Express上重新配置了几个东西,重新启动了机器等等。在某些时候,它再次开始正常工作。 It still annoys me not being able to discover what OleDb was doing for 31 seconds when connecting, but the problem is gone now (so far). 在连接时,我仍然无法发现OleDb在31秒内做了什么,但问题现在已经消失(到目前为止)。

Thanks for your help. 谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM