public TdsComm (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) { this.packetSize = packetSize; this.tdsVersion = tdsVersion; this.dataSource = dataSource; this.connectionTimeout = timeout; outBuffer = new byte[packetSize]; inBuffer = new byte[packetSize]; outBufferLength = packetSize; inBufferLength = packetSize; socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPHostEntry hostEntry = Dns.Resolve (dataSource); IPEndPoint endPoint; endPoint = new IPEndPoint (hostEntry.AddressList [0], port); // This replaces the code below for now socket.Connect (endPoint); /* FIXME: Asynchronous socket connection doesn't work right on linux, so comment this out for now. This *does* do the right thing on windows connected.Reset (); IAsyncResult asyncResult = socket.BeginConnect (endPoint, new AsyncCallback (ConnectCallback), socket); if (timeout > 0 && !connected.WaitOne (new TimeSpan (0, 0, timeout), true)) throw Tds.CreateTimeoutException (dataSource, "Open()"); else if (timeout > 0 && !connected.WaitOne ()) throw Tds.CreateTimeoutException (dataSource, "Open()"); */ stream = new NetworkStream (socket); }
public Tds70(string server, int port, int packetSize, int timeout, int lifeTime, TdsVersion version) : base(server, port, packetSize, timeout, lifeTime, version) { }
public Tds70(string server, int port, int packetSize, int timeout, TdsVersion version) : this(server, port, packetSize, timeout, 0, version) { }
public TdsComm (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) { this.packetSize = packetSize; this.tdsVersion = tdsVersion; this.dataSource = dataSource; outBuffer = new byte[packetSize]; inBuffer = new byte[packetSize]; outBufferLength = packetSize; inBufferLength = packetSize; lsb = true; IPEndPoint endPoint; bool have_exception = false; try { #if NET_2_0 IPAddress ip; if(IPAddress.TryParse(this.dataSource, out ip)) { endPoint = new IPEndPoint(ip, port); } else { IPHostEntry hostEntry = Dns.GetHostEntry (this.dataSource); endPoint = new IPEndPoint(hostEntry.AddressList [0], port); } #else IPHostEntry hostEntry = Dns.Resolve (this.dataSource); endPoint = new IPEndPoint (hostEntry.AddressList [0], port); #endif } catch (SocketException e) { throw new TdsInternalException ("Server does not exist or connection refused.", e); } try { socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IAsyncResult ares = socket.BeginConnect (endPoint, null, null); int timeout_ms = timeout * 1000; if (timeout > 0 && !ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne (timeout_ms, false)) throw Tds.CreateTimeoutException (dataSource, "Open()"); socket.EndConnect (ares); try { // MS sets these socket option socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1); } catch (SocketException) { // Some platform may throw an exception, so // eat all socket exception, yeaowww! } try { #if NET_2_0 socket.NoDelay = true; #endif socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout_ms); socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout_ms); } catch { // Ignore exceptions here for systems that do not support these options. } // Let the stream own the socket and take the pleasure of closing it stream = new NetworkStream (socket, true); } catch (SocketException e) { have_exception = true; throw new TdsInternalException ("Server does not exist or connection refused.", e); } catch (Exception) { have_exception = true; throw; } finally { if (have_exception && socket != null) { try { Socket s = socket; socket = null; s.Close (); } catch {} } } if (!socket.Connected) throw new TdsInternalException ("Server does not exist or connection refused.", null); packetsSent = 1; }
public TdsConnectionPoolManager(TdsVersion version) { this.version = version; }
public TdsConnectionPoolManager (TdsVersion version) { this.version = version; }
public TdsComm(string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) { this.packetSize = packetSize; this.tdsVersion = tdsVersion; this.dataSource = dataSource; outBuffer = new byte[packetSize]; inBuffer = new byte[packetSize]; outBufferLength = packetSize; inBufferLength = packetSize; lsb = true; IPEndPoint endPoint; bool have_exception = false; try { IPAddress ip; if (IPAddress.TryParse(this.dataSource, out ip)) { endPoint = new IPEndPoint(ip, port); } else { IPHostEntry hostEntry = Dns.GetHostEntry(this.dataSource); endPoint = new IPEndPoint(hostEntry.AddressList [0], port); } } catch (SocketException e) { throw new TdsInternalException("Server does not exist or connection refused.", e); } try { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IAsyncResult ares = socket.BeginConnect(endPoint, null, null); int timeout_ms = timeout * 1000; if (timeout > 0 && !ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(timeout_ms, false)) { throw Tds.CreateTimeoutException(dataSource, "Open()"); } socket.EndConnect(ares); try { // MS sets these socket option socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1); } catch (SocketException) { // Some platform may throw an exception, so // eat all socket exception, yeaowww! } try { socket.NoDelay = true; socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout_ms); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout_ms); } catch { // Ignore exceptions here for systems that do not support these options. } // Let the stream own the socket and take the pleasure of closing it stream = new NetworkStream(socket, true); } catch (SocketException e) { have_exception = true; throw new TdsInternalException("Server does not exist or connection refused.", e); } catch (Exception) { have_exception = true; throw; } finally { if (have_exception && socket != null) { try { Socket s = socket; socket = null; s.Close(); } catch {} } } if (!socket.Connected) { throw new TdsInternalException("Server does not exist or connection refused.", null); } packetsSent = 1; }
public Tds70 (string server, int port, int packetSize, int timeout, TdsVersion version) : base (server, port, packetSize, timeout, version) { }
public Tds (string dataSource, int port, int packetSize, int timeout, int lifeTime, TdsVersion tdsVersion) { this.tdsVersion = tdsVersion; this.packetSize = packetSize; this.dataSource = dataSource; this.columns = new TdsDataColumnCollection (); this.lifeTime = lifeTime; InitComm (port, timeout); }
public Tds (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) : this (dataSource, port, packetSize, timeout, 0, tdsVersion) { }
protected void ProcessLoginAck () { uint srvVersion = 0; GetSubPacketLength (); //Console.WriteLine ("ProcessLoginAck: B4 tdsVersion:{0}", tdsVersion); // Valid only for a Login7 request if (tdsVersion >= TdsVersion.tds70) { comm.Skip (1); srvVersion = (uint)comm.GetTdsInt (); //Console.WriteLine ("srvVersion: {0}", srvVersion); switch (srvVersion) { case 0x00000007: tdsVersion = TdsVersion.tds70; break; case 0x00000107: tdsVersion = TdsVersion.tds80; break; case 0x01000071: tdsVersion = TdsVersion.tds81; break; case 0x02000972: tdsVersion = TdsVersion.tds90; break; } //Console.WriteLine ("ProcessLoginAck: after tdsVersion:{0}", tdsVersion); } if (tdsVersion >= TdsVersion.tds70) { int nameLength = comm.GetByte (); databaseProductName = comm.GetString (nameLength); databaseMajorVersion = comm.GetByte (); databaseProductVersion = String.Format ("{0}.{1}.{2}", databaseMajorVersion.ToString("00"), comm.GetByte ().ToString("00"), (256 * comm.GetByte () + comm.GetByte ()).ToString("0000")); } else { comm.Skip (5); short nameLength = comm.GetByte (); databaseProductName = comm.GetString (nameLength); comm.Skip (1); databaseMajorVersion = comm.GetByte (); databaseProductVersion = String.Format ("{0}.{1}", databaseMajorVersion, comm.GetByte ()); comm.Skip (1); } if (databaseProductName.Length > 1 && -1 != databaseProductName.IndexOf ('\0')) { int last = databaseProductName.IndexOf ('\0'); databaseProductName = databaseProductName.Substring (0, last); } connected = true; //Console.WriteLine ("databaseProductVersion:{0}", databaseProductVersion); }
public Tds (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion) { this.tdsVersion = tdsVersion; this.packetSize = packetSize; this.dataSource = dataSource; comm = new TdsComm (dataSource, port, packetSize, timeout, tdsVersion); }