193

I'm getting a SQL Server error:

A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The handle is invalid.)

I'm running Sql Server 2008 SP1, Windows 2008 Standard 64 bit.

It's a .Net 4.0 web application. It happens when a request is made to the server. It's intermittent. Any idea how I can resolve it?

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
Chuck Conway
  • 16,287
  • 11
  • 58
  • 101
  • database and web server are on same server (Shared Memory). I would suspect a bug in your code... – Mitch Wheat Jun 03 '10 at 03:18
  • 3
    This may occur if the database was created on an older version of SQL Express/MSDE that set AUTO_CLOSE to True. Or the SQL Server service instance was restarted. – devstuff Jul 19 '10 at 04:25
  • @devstuff that's good to know. I cant' remember if it was an older database or not. – Chuck Conway Dec 05 '10 at 19:30
  • I got this error because something went wrong with the session database. Only restarting the web applications that were using it could fix the issue. – ab_732 Sep 18 '12 at 18:40
  • 1
    I can be cause by a pending action on your db. this result in a DB lock. – pix Dec 08 '14 at 19:11
  • 4
    The marked answer isn't an answer. The answer by Michael Olivero below that actually provides content and following it solved the problem when I ran into it. (Manually closing the temporary web server on my dev machine.) I recommend the answer be changed. – Adam Miller Jan 07 '15 at 20:26
  • I never found the answer. It was random. Once I rebooted the machine it went away and I haven't see the issue again. – Chuck Conway Jul 19 '10 at 03:42
  • Wow, is there any other way to solve this problem? I'm getting it on a dev server where everyting where still doing fine before last week. Now, it seems that we can make a READ but not an UPDATE, INSERT or DELETE. I need an answer please. – Simon Dugré Jul 19 '10 at 12:48
  • I tried restarting IIS, restarting the web app, restarting the app pool. All of them only fixes the problem temporarily (i.e. the problem occurred again in a few hours). I restarted the machine a day ago, and have not seen the problem yet. – Hong Oct 09 '13 at 02:46
  • open `cmd.exe`, type `iisreset` - it worked – codingbiz Dec 03 '12 at 06:34
  • On my dev computer, I just shut down the Visual Studio IIS debug server and then restarted the project website. worked. – LaundroMatt Jul 03 '12 at 04:13
  • Just had the same thing on an ASP.Net web app. I restarted the application pool and it was OK, no need to reboot either box – Andy Apr 28 '12 at 18:22
  • I had the same issue and restarting IIS fixed it. – Rismo Jan 23 '12 at 16:29
  • I had the same issue and the restart fixed it on my dev box. Thanks. – Brad8118 Oct 24 '11 at 21:24
  • I had the same issue as @Simon, using the dev web server that devenv fires up. Could read, but not delete. Anyway, restarting the server fixed it. Have only had the problem once in several months. – Drew Noakes Dec 05 '10 at 19:01
  • Nothing fixed it for me, except restarting the workstation. – Alireza Oct 28 '16 at 06:49
  • I didn't even restart anything to fix it. I just dragged the break point up and reran the code and it worked. I also have a windows service that logs this error occasionally, but it always continues working on it's own after encountering the error once or twice. – Hagelt18 Oct 17 '16 at 14:54
  • Got the error when doing Import-SPWeb from PowerShell on a SharePoint box. iisreset helped. – Heinrich Ulbricht Jul 09 '14 at 12:43
  • i restarted the sql server instance and that fixed it for me – ladieu Jul 15 '13 at 17:10
  • 5
    @Flexo This is closed as off-topic? I just had it happen to me with brand new installs of VS 2017 and MS SQL 2016 Enterprise. While it was working just fine with VS 2015 Community. – Edward Jun 10 '17 at 01:20
  • 4
    This shouldn't be off-topic. The issue has nothing to do with the code in use, so an MCVE cannot be created for it. Also, the closure reason states: `this one was resolved in a manner unlikely to help future readers` - but 179k people have come across this question. – Nisarg Shah Apr 25 '18 at 08:40
  • this may help: https://dba.stackexchange.com/questions/64409/a-transport-level-error-has-occurred-when-sending-the-request-to-the-server/316060#316060 – HamedH Aug 25 '22 at 15:08

21 Answers21

124

The database connection is closed by the database server. The connection remains valid in the connection pool of your app; as a result, when you pickup the shared connection string and try to execute it's not able to reach the database. If you are developing Visual Studio, simply close the temporary web server on your task bar.

If it happens in production, resetting your application pool for your web site should recycle the connection pool.

Michael Olivero
  • 1,241
  • 1
  • 8
  • 2
  • 1
    This one is the actual answer. – TheHuge_ Nov 14 '16 at 16:55
  • 7
    In my particular case, I had a `MultipleActiveResultSets=True` setting in connection string that caused the same error. – Semyon Vyskubov May 04 '17 at 08:16
  • For me running an iisreset command from an elevated command prompt resolved the issue (I was debugging from Visual Studio against IIS) – Malcolm Swaine Jul 25 '21 at 15:26
  • I got this error due to SQL Server not liking one of my commented out lines of SQL. My advice is to start with the simplest code to validate that it is not a connection issue and then work up from there. The commented out line was --EXEC master..xp_cmdshell 'bcp ... for which the remote computer did not have permission to run. There is an almost identical line later on in the code that was accepted, so I think this is some vague security patch error also. You would think a commented out line would have no affect on connectivity issues, but here we are. – Dustin Morrison Sep 26 '22 at 16:12
19

Try the following command on the command prompt:

netsh interface tcp set global autotuning=disabled

This turns off the auto scaling abilities of the network stack

David Fraser
  • 6,475
  • 1
  • 40
  • 56
Simmo
  • 3,101
  • 3
  • 16
  • 15
  • 26
    Can you provide some details on what that actually does? Are there any reasons against setting such a value globally? – Drew Noakes Dec 05 '10 at 19:02
  • 1
    it turns off the auto scaling abilities of the network stack. – Simmo Dec 07 '10 at 12:41
  • Does not work in Windows XP SP3. Netsh interface does not have tcp sub command in Windows XP, however it works well in Windows 7 SP1. – Narayanan Apr 24 '12 at 04:07
  • I know this is old, but this was the only solution that worked for me (most issues/solutions revolve around a webserver/app, my situation is desktop app and local network server, no IIS or anything like that). Why would turning off autotuning/autoscaling fix this problem? – Trent Nov 21 '14 at 05:59
  • It gives me an error **"Set global command failed on IPv4 The parameter is incorrect."** – 3 rules Oct 14 '16 at 06:26
  • 1
    in my case, ReOpen of SQL Server Management Studio solved the problem – Alex Apr 11 '17 at 08:51
  • This dramatically reduced the number of occurrences, but did not completely eliminate the errors. It went from around 40 down to 2 per hour. – Louis Somers Jan 27 '23 at 11:51
17

I had the same problem. I restarted Visual Studio and that fixed the problem

piris
  • 1,547
  • 3
  • 22
  • 26
14

Transport level errors are often linked to the connection to sql server being broken ... usually network.

Timeout Expired is usually thrown when a sql query takes too long to run.

So few options can be :

  1. Check for the connection in VPN (if used) or any other tool
  2. Restart IIS
  3. Restart machine
  4. Optimize sql queries.
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
NG.
  • 5,695
  • 2
  • 19
  • 30
13

For those not using IIS, I had this issue when debugging with Visual Studio 2010. I ended all of the debugger processes: WebDev.WebServer40.EXE which solved the issue.

jth_92
  • 1,120
  • 9
  • 23
  • Please tell the steps to on how you ended those process. I am beginner and I don't know what you mean by "ended all the debugger process" – Unbreakable Aug 09 '17 at 20:03
  • @Unbreakable I just used Task Manager. In the task manager, you can see all the running processes with the name WebDev.WebServer40.EXE. See https://betanews.com/2015/10/08/how-to-kill-a-windows-process/ for how to kill a windows process. – jth_92 Aug 11 '17 at 00:11
7

All you need is to Stop the ASP.NET Development Server and run the project again

pancake
  • 590
  • 7
  • 24
6

Look at the MSDN blog which details out this error:

Removing Connections

The connection pooler removes a connection from the pool after it has been idle for a long time, or if the pooler detects that the connection with the server has been severed.

Note that a severed connection can be detected only after attempting to communicate with the server. If a connection is found that is no longer connected to the server, it is marked as invalid.

Invalid connections are removed from the connection pool only when they are closed or reclaimed.

If a connection exists to a server that has disappeared, this connection can be drawn from the pool even if the connection pooler has not detected the severed connection and marked it as invalid.

This is the case because the overhead of checking that the connection is still valid would eliminate the benefits of having a pooler by causing another round trip to the server to occur.

When this occurs, the first attempt to use the connection will detect that the connection has been severed, and an exception is thrown.

Basically what you are seeing is that exception in the last sentence.

A connection is taken from the connection pool, the application does not know that the physical connection is gone, an attempt to use it is done under the assumption that the physical connection is still there.

And you get your exception.

There are a few common reasons for this.

  1. The server has been restarted, this will close the existing connections.

In this case, have a look at the SQL Server log, usually found at: C:\Program Files\Microsoft SQL Server\\MSSQL\LOG

If the timestamp for startup is very recent, then we can suspect that this is what caused the error. Try to correlate this timestamp with the time of exception.

2009-04-16 11:32:15.62 Server Logging SQL Server messages in file ‘C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG’.

  1. Someone or something has killed the SPID that is being used.

Again, take a look in the SQL Server log. If you find a kill, try to correlate this timestamp with the time of exception.

2009-04-16 11:34:09.57 spidXX Process ID XX was killed by hostname xxxxx, host process ID XXXX.

  1. There is a failover (in a mirror setup for example) again, take a look in the SQL Server log.

If there is a failover, try to correlate this timestamp with the time of exception.

2009-04-16 11:35:12.93 spidXX The mirrored database “” is changing roles from “PRINCIPAL” to “MIRROR” due to Failover.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
5

If you are connected to your database via Microsoft SQL Server Management, close all your connections and retry. Had this error when connected to another Azure Database, and worked for me when closed it. Still don't know why ..

watabou
  • 59
  • 1
  • 1
  • This was a fix that worked for me. I shut down SQL Server Management Studio and then I never saw this error again. – Beevik Sep 11 '13 at 18:43
  • i can't believe it, but this actually worked. I could be that the server was saturated at first moment, who knows. thanks anyway! – jrivam Aug 05 '20 at 12:34
4

Was getting this, always after about 5 minutes of operation. Investigated and found that a warning from e1iexpress always occurred before the failure. This apparently is an error having to do with certain TCP/IP adapters. But changing from WiFi to hardwired didn't affect it.

So tried Plan B and restarted Visual Studio. Then it worked fine.

On closer study I noticed that, when working correctly, the message The Thread '<No Name>' has exited with code 0 occurred at almost exactly the time the run crashed in previous attempts. Some Googling reveals that that message comes up when (among other things) the server is trimming the thread pool.

Presumably there was a bogus thread in the thread pool and every time the server attempted to "trim" it it took the app down.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
3

You get this message when your script make SQL Service stopped for some reasons. so if you start SQL Service again perhaps your problem will be resolved.

Mohammad Sheykholeslam
  • 1,379
  • 5
  • 18
  • 35
  • Kindly provide steps to on how to start SQL Service. I am a beginner and I just created an asp.net mvc 5 application. and when I run "enable-migrations" everything is fine then I run "add-migration "sdfd" everything is fine and then when I click on update-database I get this error. please guide me – Unbreakable Aug 09 '17 at 19:24
3

I know this may not help everyone (who knows, maybe yes), but I had the same problem and after some time, we realized that the cause was something out of the code itself.

The computer trying to reach the server, was in another network, the connection could be established but then dropped.

The way we used to fix it, was to add a static route to the computer, allowing direct access to the server without passing thru the firewall.

route add –p YourServerNetwork mask NetworkMask Router 

Sample:

route add –p 172.16.12.0 mask 255.255.255.0 192.168.11.2 

I hope it helps someone, it's better to have this, at least as a clue, so if you face it, you know how to solve it.

coloboxp
  • 494
  • 8
  • 15
2

I got the same error in Visual Studion 2012 development environment, stopped the IIS Express and rerun the application, it started working.

Murthy M
  • 119
  • 1
  • 2
2

I had the same issue. I solved it, truncating the SQL Server LOG. Check doing that, and then tell us, if this solution helped you.

Lucas
  • 21
  • 1
2

For me the solution was totally different.

In my case I had an objectsource which required a datetimestamp parameter. Even though that ODS parameter ConvertEmptyStringToNull was true 1/1/0001 was being passed to SelectMethod. That in turn caused a sql datetime overflow exception when that datetime was passed to the sql server.

Added an additional check for datetime.year != 0001 and that solved it for me.

Weird that it would throw a transport level error and not a datetime overflow error. Anyways..

KonaRin
  • 99
  • 1
  • 2
2

In my case the "SQL Server" Server service stopped. When I restarted the service that enabled me to run the query and eliminate the error.

Its also a good idea to examine your query to find out why the query made this service stop

enter image description here

user3447136
  • 141
  • 1
  • 3
1

For me the answer is to upgrade the OS from 2008R2 to 2012R2, the solution of iisreset or restart apppool didn't work for me. I also tried to turn of TCP Chimney Offload setting, but I didn't restart the server because it is a production server, which didn't work either.

Bruce Liu
  • 384
  • 3
  • 6
1

We encountered this error recently between our business server and our database server. The solution for us was to disable "IP Offloading" on the network interfaces. Then the error went away.

Dave
  • 11
  • 1
1

One of the reason I found for this error is 'Packet Size=xxxxx' in connection string. if the value of xxxx is too large, we will see this error. Either remove this value and let SQL server handle it or keep it low, depending on the network capabilities.

1

It happened to me when I was trying to restore a SQL database and checked following Check Box in Options tab,

enter image description here

As it's a stand alone database server just closing down SSMS and reopening it solved the issue for me.

Muhammad Raja
  • 1,970
  • 3
  • 28
  • 46
1

This occurs when the database is dropped and re-created some shared resources is still considering the database still exists, so when you re-run execute query to create tables in the database after it was re-created the error will not show again and Command(s) completed successfully. message will show instead of the error message Msg 233, Level 20, State 0, Line 0 A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.).

Simply ignore this error when you are dropping and recreating databases and re-execute your DDL queries with no worries.

Ashraf Sada
  • 4,527
  • 2
  • 44
  • 48
0

I faced the same issue recently, but i was not able to get answer in google. So thought of sharing it here, so that it can help someone in future.

Error:

While executing query the query will provide few output then it will throw below error.

"Transport level error has occurred when receiving output from server(TCP:provider,error:0- specified network name is no longer available"

Solution:

  1. Check the provider of that linked server
  2. In that provider properties ,Enable "Allow inprocess" option for that particular provider to fix the issue.
PM 77-1
  • 12,933
  • 21
  • 68
  • 111