简体   繁体   English

IIS 10 / SQL Server 2017 / 与经典 ASP 的连接速度非常慢

[英]IIS 10 / SQL Server 2017 / very slow connections with classic ASP

I've been running classic ASP / SQL Server 2008 R2 / Windows Server 2012 R2 / IIS 8 for about 10-15 years;我已经运行经典的 ASP / SQL Server 2008 R2 / Windows Server 2012 R2 / IIS 8 大约 10-15 年; no problem.没问题。 But I'm trying to get these same scripts to run on a new machine with Windows Server 2016 (IIS 10) and SQL Server 2017, and am having problems with connections to the databases.但我试图让这些相同的脚本在装有 Windows Server 2016 (IIS 10) 和 SQL Server 2017 的新机器上运行,并且在连接数据库时遇到问题。 (And rewriting them in ASP.NET isn't an option for right now). (并且在 ASP.NET 中重写它们现在不是一个选项)。

For example, I'll create a connection to the database:例如,我将创建一个到数据库的连接:

set conn = server.CreateObject("ADODB.Connection")  
conn.ConnectionTimeout=120  
conn.Open("Provider=sqloledb;Data Source=(local);Initial Catalog=myDatabase;Integrated Security=SSPI")

First problem, it takes two seconds (exactly two seconds, for every connection) to create the connection.第一个问题,创建连接需要两秒钟(每个连接正好两秒钟)。 And even though the connection is supposed to stay open, subsequent connections (same db; same connection string) on that page or another page take exactly two seconds (even though I've set the ConnectionTimeout to 120 seconds).即使连接应该保持打开状态,该页面或另一个页面上的后续连接(相同的数据库;相同的连接字符串)也需要两秒钟(即使我已将 ConnectionTimeout 设置为 120 秒)。

Second problem (more serious), it then takes two seconds (almost exactly two seconds) to do any operation on that connection, even if it's just one row, eg:第二个问题(更严重),然后需要两秒钟(几乎正好是两秒钟)对该连接执行任何操作,即使它只是一行,例如:

sql = "update myTable set zipCode = 91839 where ID = 12345"  
conn.execute(sql)

And then if I do another update (for example) on just one row, it takes another two seconds (almost exactly two seconds):然后,如果我只对一行进行另一次更新(例如),则需要另外两秒钟(几乎正好是两秒钟):

sql = "update myTable set zipCode = 02930 where ID = 67890"  
conn.execute(sql)

With the previous setup (SQL Server 2008 R2 / Windows Server 2012 R2 / IIS 8), it took a couple of milliseconds to create a connection, and then simple updates like those above would take 1-2 ms.使用之前的设置(SQL Server 2008 R2 / Windows Server 2012 R2 / IIS 8),创建连接需要几毫秒,然后像上面这样的简单更新需要 1-2 毫秒。 But now every connection and every operation on that connection takes two seconds + the amount of time that it should take (eg 2 ms).但是现在每个连接和该连接上的每个操作都需要两秒 + 它应该花费的时间量(例如 2 毫秒)。

I'm guessing that somehow the default settings for SQL Server connections in IIS 10 have changed and that's what's causing the problem, but I'm not sure.我猜想 IIS 10 中 SQL Server 连接的默认设置以某种方式发生了变化,这就是导致问题的原因,但我不确定。 BTW, I'm using the default IUSR account in IIS to connect to SQL Server (both in the old setup and now).顺便说一句,我使用 IIS 中的默认 IUSR 帐户连接到 SQL Server(在旧设置和现在)。

As per my comment on the question was correct, I will just make it as an answer for everyone else:根据我对这个问题的评论是正确的,我将把它作为其他人的答案:

Please try the following (each one or a combination of) change on your connection string:请尝试对您的连接字符串进行以下(每个或组合)更改:

Integrated Security=True
    Provider=SQLNCLI11

The SSPI works well with both SQLClient & OleDB that is why it is usually preferred but maybe the compatibility portion makes it slower as it tries to gracefully make everything correct. SSPI 与 SQLClient 和 OleDB 都可以很好地工作,这就是为什么它通常是首选的原因,但也许兼容性部分使它变慢,因为它试图优雅地使一切正确。 The provider portion change from sqloledb to SQLNCLI11 forces the engine to use SQLClient as most likely you are using SQL Server, no need to go for compatibility again (let us say switching to Oracle).提供程序部分从 sqloledb 更改为 SQLNCLI11 会强制引擎使用 SQLClient,因为您很可能正在使用 SQL Server,无需再次寻求兼容性(假设切换到 Oracle)。 Compatibility takes a performance hit sometimes.兼容性有时会影响性能。

Reference(s):参考):

What is the difference between Integrated Security = True and Integrated Security = SSPI? Integrated Security = True 和 Integrated Security = SSPI 有什么区别?

Difference between Sql Connection and OLEDB Connection Sql连接和OLEDB连接的区别

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

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