Hi,
Using ADO.NET and trying to get the server edition it generate an exception on Mono under Linux environment.
Example:
using (var connection = new SqlConnection(connString))
{
connection.Open();
foreach (var cmdText in new[] {"select serverproperty('EngineEdition')", "SELECT 1"})
{
using (var command = new SqlCommand(cmdText, connection))
{
using (var reader = command.ExecuteReader())
{
reader.Read();
Console.WriteLine(reader.GetInt32(0));
}
}
}
}
Exception generated:
System.IO.IOException: Read failure ---> System.Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Sockets.Socket.Receive (System.Byte[] buffer, Int32 offset, Int32 size, SocketFlags flags) [0x0006b] in /build/buildd/mono-3-3.2.4/mcs/class/System/System.Net.Sockets/Socket.cs:1561
at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00067] in /build/buildd/mono-3-3.2.4/mcs/class/System/System.Net.Sockets/NetworkStream.cs:378
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00078] in /build/buildd/mono-3-3.2.4/mcs/class/System/System.Net.Sockets/NetworkStream.cs:380
at Mono.Data.Tds.Protocol.TdsComm.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in /build/buildd/mono-3-3.2.4/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs:611
First I noticed this behavior by using Entity Framework 6. I opened a discussion under EF Codeplex: https://entityframework.codeplex.com/discussions/538142
Because EF try to get SQL Version, at the begin of connection, this exception does not allow to be used in a Linux environment. There is a workaround for EF to avoid the issue (link above).
Anyway does not belong to EF and may be reproduced using the snippet above.
Thank you !
Liviu