Bug 28151 - System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: The socket is not connected
Summary: System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException:...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: 3.12.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-18 10:54 UTC by Joe
Modified: 2017-09-01 09:29 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Joe 2015-03-18 10:54:08 UTC
I tried to connect to a SQL Server by following code:

public static string TestDB1(){

            string s = "";
            try{
                SqlConnection conn = new SqlConnection("Server=**;Database=**;User ID=**;Password=**");
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select count(1) from sites";

                using(IDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)){

                    if(dr.Read()){
                        s = dr[0].ToString();
                    }
                }
                return s;

            }catch(Exception e){
                return e.ToString ();
            }
		}

It works fine if I put the code to a "console application", but it throws errors if I put the code to a MVC project. Please note, the error doesn't come up all the time, but just sometimes it works without any error, sometimes it doesn't. 

I also tried with different solutions, like close the db connection explicitly, same result. I'm not sure if it matters, but for the MVC project I used, I have a lot of other dlls that I need to reference. Also, if I put the code into a fresh new MVC project, it works like the console application does. So it turns out that something might be different for my existing MVC project, but I just cannot tell what it is. 

Anyone has any tips?

System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: The socket is not connected at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00055] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.Net.Sockets/Socket.cs:1839 at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x0006e] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:415 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x0008e] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:418 at Mono.Data.Tds.Protocol.TdsComm.SendPhysicalPacket (Boolean isLastSegment) [0x000a2] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:812 at Mono.Data.Tds.Protocol.TdsComm.SendPacket () [0x0001f] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:786 at Mono.Data.Tds.Protocol.Tds70.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x005a3] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs:389 at Mono.Data.Tds.Protocol.Tds80.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds80.cs:87 at System.Data.SqlClient.SqlConnection.Open () [0x0023b] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs:595 System.IO.IOException: Write failure ---> System.Net.Sockets.SocketException: The socket is not connected at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags) [0x00055] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.Net.Sockets/Socket.cs:1839 at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x0006e] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:415 --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x0008e] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.Net.Sockets/NetworkStream.cs:418 at Mono.Data.Tds.Protocol.TdsComm.SendPhysicalPacket (Boolean isLastSegment) [0x000a2] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:812 at Mono.Data.Tds.Protocol.TdsComm.SendPacket () [0x0001f] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:786 at Mono.Data.Tds.Protocol.Tds70.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x005a3] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs:389 at Mono.Data.Tds.Protocol.Tds80.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds80.cs:87 at System.Data.SqlClient.SqlConnection.Open () [0x0023b] in /private/tmp/source-mono-mac-3.12.99-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs:595
Comment 1 Joe 2015-03-18 11:19:25 UTC
one more thing, for my MVC project, sometimes, it can work one time, but when I refresh my page which will fire the method again, it throw the exception.
Comment 2 Adi 2015-06-14 10:42:10 UTC
I had this problem - the exception couldn't be caught from a different thread of mono.  In my case the Server's mono runtime failed when hitting refresh several times in the clients browser.  The exception is normal (I do expect to receive it as sometimes socket might be closed and there are still requests in the air). But I was expecting to catch them..

Anyhow - the important thing is I had it with mono v4.1.0 (and had to remark the exception throwing at mcs/class/System/System.Net/NetwrokStream.cs.  And the good news it is working with mono 4.3.0 (master/2eb59a6) (linux / ubuntu)

Note You need to log in before you can comment on or make changes to this bug.