SQL Server "Network Path Not Found" Occurs occasionally and often in different environments

A similar (if not the same question as) Could not find a random event on the network, but I have the code to reproduce the problem, so I want to ask again how it appears to be a real problem, independent of hardware and can be reproduced.

Here's the error:

provider: Named Pipes provider, error: 40 - could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): the network path was not found in System.Data.ProviderBase.DbConnectionPool.TryGetConnection (DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal and connection) in System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen ()

To reproduce this, I created a console application that starts every minute (we also have a Dapper DAL test, therefore, a parameter):

internal class Program { private static int _totalOpenConnections; private static readonly Stopwatch Timer = new Stopwatch(); private static bool _hasError; private static int Main(string[] args) { var list = Enumerable.Range(1, Settings.Default.TotalCommandsToExecute); // simple ADO.NET test if (args.Length > 0 && args[0].Equals("ado", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Beginning ADO.NET Test..."); Timer.Restart(); Parallel.ForEach(list, new ParallelOptions {MaxDegreeOfParallelism = Settings.Default.ConcurrentCount}, i => AsyncContext.Run(async () => { try { PrintStatus(i); await TestADONet(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); _hasError = true; } })); Timer.Stop(); Console.WriteLine($"Completed ADO.NET Test in {Timer.ElapsedMilliseconds} ms"); } if (_hasError) return 1; return 0; } private static void PrintStatus(int index) { Console.WriteLine( $"Started: {index} of {Settings.Default.TotalCommandsToExecute}\tCurrently Open: {_totalOpenConnections}"); } private static async Task TestADONet() { using (var conn = new SqlConnection(Settings.Default.TestConnection)) { await conn.OpenAsync(); Interlocked.Increment(ref _totalOpenConnections); var command = new SqlCommand("SELECT 1 Field1, 2 Field2, 3 Field3", conn); var reader = await command.ExecuteReaderAsync(); while (reader.Read()) { var result = new TestEntity { Field1 = reader.GetInt32(0), Field2 = reader.GetInt32(1), Field3 = reader.GetInt32(2) }; } } Interlocked.Decrement(ref _totalOpenConnections); } public class TestEntity { public int Field1 { get; set; } public int Field2 { get; set; } public int Field3 { get; set; } } } 

Application parameters ConcurrentCount = 100 and TotalCommandsToExecute = 200. The idea is to successfully delete the connection pool using asynchronous commands.

This application reproduces it, however it also occurred in production in console applications, web applications (ASP.NET MVC and ASP.NET WebForms).

This also happens in a rather random manner. We had Rackspace, and some database administrators scanned the environment on this issue to no avail, which led to this application that played it in the development environment.

The connection string is quite soft, with the form "Data Source =; Database =; User Id =; Password ="

SQL Server 2014, but it happened against two separate servers (dev / rackspace)

The request in the test is intentionally benign

"SELECT 1 Field1, 2 Field2, 3 Field3"

This test uses Nito.AsyncEx, the only system build used here to get async support. Again, the problem occurs in other applications that do not use this assembly, so I do not think that this is a problem - let me know if not, and I will reproduce it in a different way.

ANY ideas are greatly appreciated!

0
c # sql-server networking named-pipes
source share
1 answer

The problem was named pipes. This can be expressed more in a virtual machine (spec on the links below). Using TCP / IP, adding tcp: to the connection string and indicating that the port solved the problem.

Some related cases:

Conclusion Always explicitly uses TCP / IP if SQL Server is not on the same computer. You can configure SQL Server to not accept named pipes, but in the future I will just add it to the connection strings.

0
source share

All Articles