简体   繁体   English

网站无法连接到SQL Server,但控制台应用程序可以

[英]Website can't connect to SQL Server, but console app can

I have a SQL Server with two databases, a production database and a development database. 我有一个带有两个数据库的SQL Server,一个生产数据库和一个开发数据库。 The .net 2.0 website hitting the production database with manual SqlConnection code is working fine. 使用手动SqlConnection代码访问生产数据库的.net 2.0网站运行正常。 The other database is being hit from a newer ASP.NET MVC app using Entity Framework 6.2 and is getting timeout issues. 正在使用Entity Framework 6.2从较新的ASP.NET MVC应用程序中命中另一个数据库,并且该数据库遇到超时问题。 The timeout takes 30 seconds the first time, but the page comes back almost instantaneously on subsequent refreshes. 首次超时时间为30秒,但随后的刷新几乎立即返回页面。 Both websites are on the same box as the database, so are only using "localhost" to connect. 这两个网站都与数据库位于同一框上,因此仅使用“ localhost”进行连接。 They are using SQL Server user logins, not Windows authentication. 他们使用的是SQL Server用户登录名,而不是Windows身份验证。

I copied the .edmx and .tt files into a .net console app and that app has no problem hitting the database with the exact same linq query and pulling the same data that is failing. 我将.edmx.tt文件复制到了.net控制台应用程序中,该应用程序使用完全相同的linq查询访问数据库并提取失败的相同数据没有问题。

I then created a new web site and copied just that same code into an aspx page. 然后,我创建了一个新网站,并将相同的代码复制到了一个aspx页面中。 It fails the first time with a timeout, and then works on subsequent attempts (and a week ago, the main dev site was doing the same thing). 它第一次失败并超时,然后在随后的尝试中工作(一周前,主开发站点正在执行相同的操作)。

I separated the dev database from the SQL Server 2008 R2 server and attached it to a newly installed instance of SQL Server Express on a different port, and get the same results. 我将开发数据库与SQL Server 2008 R2服务器分离,并将其附加到新安装的SQL Server Express实例的其他端口上,并获得相同的结果。

The web server is windows server 2008 standard 32-bit. Web服务器是Windows Server 2008标准32位。 I copied both websites and the console application to a new box (I thought was 2016, but it turns out it is 2008 standard 64-bit) and get the same results. 我将网站和控制台应用程序都复制到了一个新盒子中(我以为是2016年,但事实证明它是2008年标准的64位),并获得了相同的结果。

The dev site was working up until a couple of months ago. 开发站点的工作一直持续到几个月前。 The client was using local user accounts for everything, but had a domain and wanted to do testing with windows authentication for an old vb app that hits the same database, and I had started migrating testing accounts to the domain. 客户端使用本地用户帐户进行所有操作,但是有一个域,并希望使用Windows身份验证对命中相同数据库的旧vb应用进行测试,因此我开始将测试帐户迁移到域中。 When the client tried to later, for an unrelated reason, change his password, we discovered that he was already using a domain account, but that his laptop could not connect to the domain. 当客户端由于不相关的原因稍后尝试更改密码时,我们发现他已经在使用域帐户,但是他的笔记本电脑无法连接到该域。 We found several other computers that could not connect, even though the machines I had connected to the domain during my testing were working fine. 我们发现其他几台无法连接的计算机,即使我在测试期间连接到域的计算机运行正常。 An outside network "friend" was brought in to figure out what was going on. 引入了外部网络“朋友”以了解发生了什么。 At that point, I lost all track of what was actually done. 那时,我对实际完成的工作一无所知。 I know that different network and domain configurations were tried and didn't fix the domain issues, but I don't know what. 我知道尝试了不同的网络和域配置,但不能解决域问题,但是我不知道是什么。 However, the production site was never rendered inoperative. 但是,生产现场从未停止运作。

I have no idea what is going on. 我不知道发生了什么。 Does anyone else? 还有其他人吗?

Oh, and in case it was a provider issue, I've also tried manual connection using OleDbconnection from the web app, and it also fails with the Timeout issue. 哦,如果是供应商问题,我也尝试过使用Web应用程序中的OleDbconnection手动连接,并且因超时问题而失败。

Update: I spun up a new DataCenter 2016 box, installed IIS and .net on it and copied the website to that box. 更新:我启动了一个新的DataCenter 2016框,在其上安装了IIS和.net,并将网站复制到了该框。 It has no problems hitting the database and pulling the data from the other server. 命中数据库并从其他服务器提取数据没有问题。 I know patches and such were updated on the original box while the domain and network were being manipulated, but I don't know how far behind they were. 我知道,在操纵域和网络时,补丁和此类补丁已在原始包装箱上进行了更新,但我不知道它们有多远。 I suspect that some patch changed some default or inherited .net configuration options or something. 我怀疑某些修补程序更改了某些默认或继承的.net配置选项或其他内容。 I did do a "repair" on the .net installation, and that didn't make a difference. 我确实对.net安装进行了“修复”,但这没有什么不同。 However, with the production site working fine, I'm not currently willing to uninstall .net or anything else. 但是,由于生产站点工作正常,我目前不愿意卸载.net或其他任何东西。 I'm afraid I would risk pushing this same error into the production site and the client would be screwed. 恐怕我会冒着将相同的错误推入生产现场的风险,并且客户会被搞砸。

It seems that for some reason, the timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. 似乎由于某种原因,尝试消耗登录前握手确认时超时时间已过去。 Try increasing the connect timeout property in your connection string to 60 or more. 尝试将连接字符串中的连接超时属性增加到60或更多。 Default is 15 (in seconds). 默认值为15(以秒为单位)。

Example: Data Source=(LocalDB)\\v11.0;Integrated Security=True; 示例:数据源=(LocalDB)\\ v11.0;集成安全性= True; Connect Timeout=30 连接超时= 30

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

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