Excel 2010 VBA adodb 连接到 SQL Server 2010 登录超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15382559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:00:32  来源:igfitidea点击:

Excel 2010 VBA adodb connection to SQL Server 2010 login timeout

sql-servervbatimeoutadodb

提问by Jonathan P.

I spent several hours on this error and I can't find any relevant solution in my brain or on the internet.

我在这个错误上花了几个小时,但在我的大脑或互联网上找不到任何相关的解决方案。

I have written a few VBA macros in Excel 2010 that connect to a SQL Server 2008 database on my computer and get some information back. I used them for a few weeks and they worked fine.

我在 Excel 2010 中编写了一些 VBA 宏,它们连接到我计算机上的 SQL Server 2008 数据库并获取一些信息。我用了几个星期,它们工作得很好。

2 days ago I set up SQL Server 2008 and Excel 2010 on a new computer, and tried to import my database and my VBA macros.

2 天前,我在一台新计算机上设置了 SQL Server 2008 和 Excel 2010,并尝试导入我的数据库和我的 VBA 宏。

Here is the issue: When trying to use the macros, excel stop answering then crashed with a catastrophic failure when I forced the close. So I created a new empty database (called PR_db), created a new excel file, and tried to make just a simple connexion to the database with the following code:

问题是:当我尝试使用宏时,excel 停止回答,然后当我强制关闭时发生灾难性故障而崩溃。所以我创建了一个新的空数据库(称为 PR_db),创建了一个新的 excel 文件,并尝试使用以下代码与数据库进行简单的连接:

Public Const cString = "Provider=SQLOLEDB; Data Source=tosh-TOSH; Initial Catalog=PR_db;Trusted_Connection=yes"

Dim objMyConn As Object
Set objMyConn = CreateObject("ADODB.Connection")
objMyConn.Open
objMyConn.Close

This code worked for weeks on my previous computer. But on the new computer it results in a "login timeout error" 9 times out of 10 (Once in a while it works, then when I try again it doesn't work, even though I didn't change anything!)

此代码在我以前的计算机上工作了数周。但是在新计算机上,10 次中有 9 次会导致“登录超时错误”(偶尔它会起作用,然后当我再次尝试时它不起作用,即使我没有更改任何内容!)

I'm really lost here... any idea ?

我真的迷路了......知道吗?

采纳答案by Jonathan P.

I recommend reading more about connection strings.
http://www.connectionstrings.com/

我建议阅读有关连接字符串的更多信息。
http://www.connectionstrings.com/