OleDB 连接仅在调试时有效

发布于 2024-09-03 11:24:42 字数 1410 浏览 3 评论 0原文

我有一个 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;"

如果我调试该应用程序,则连接工作正常。如果我从 Windows 资源管理器运行该应用程序(相同的调试编译),30 秒后,我会在 Open() 行中收到“OleDBException:登录超时已过期”。 奇怪的是,即使我将调试器附加到 exe,也会发生异常。我可以看到连接字符串是正确的,一切看起来都很好。我也无法在 SQL Express 错误日志或 SQL 活动监视器中找到任何额外信息。

如果有帮助,这里是例外:

    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 have a C# application that connects to a named SQL Express instance on the local machine using OleDBConnection:

_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.
The strange thing is the exception happens even if I attach the debugger to the 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风柔一江水 2024-09-10 11:24:42

我修好了。不幸的是,我真的不知道怎么做:我删除了输出文件夹,重置了一些项目引用,重新配置了 SQL Express 上的一些内容,重新启动了机器,等等。在某个时候,它再次开始正常工作。
连接时 31 秒内无法发现 OleDb 正在做什么仍然让我很恼火,但问题现在已经消失了(到目前为止)。

感谢您的帮助。

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.
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).

Thanks for your help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文