Пример #1
0
 public SniPacket(SafeHandle sniHandle) : base(IntPtr.Zero, true)
 {
     SniNativeMethodWrapper.SNIPacketAllocate(sniHandle, SniNativeMethodWrapper.IOType.WRITE, ref handle);
     if (IntPtr.Zero == handle)
     {
         throw SQL.SniPacketAllocationFailure();
     }
 }
Пример #2
0
 private SniLoadHandle() : base(IntPtr.Zero, true)
 {
     SniStatus = SniNativeMethodWrapper.SNIInitialize();
     if (TdsEnums.SNI_SUCCESS != SniStatus)
     {
         throw new Exception("Failed to Load spi");
     }
     handle = (IntPtr)1; // Initialize to non-zero dummy variable.
 }
Пример #3
0
        public TdsStreamNative(string serverName, int timeout)
        {
            var status = SniLoadHandle.SingletonInstance.SniStatus;

            _sniNativeHandle = new SniNativeHandle(serverName, timeout, out InstanceNameBytes);
            ServerSpn        = Encoding.ASCII.GetString(_sniNativeHandle.SpnBuffer);
            InstanceName     = "";
            _sspi            = new SspiNative(_sniNativeHandle, _sniNativeHandle.SpnBuffer);
            SniNativeMethodWrapper.SniGetConnectionId(_sniNativeHandle, ref _clientConnectionId);
        }
Пример #4
0
        protected override bool ReleaseHandle()
        {
            // NOTE: The SafeHandle class guarantees this will be called exactly once.
            var ptr = handle;

            handle = IntPtr.Zero;
            if (IntPtr.Zero == ptr)
            {
                return(true);
            }
            return(0 == SniNativeMethodWrapper.SNIClose(ptr));
        }
Пример #5
0
 protected override bool ReleaseHandle()
 {
     if (handle == IntPtr.Zero)
     {
         return(true);
     }
     if (TdsEnums.SNI_SUCCESS == SniStatus)
     {
         SniNativeMethodWrapper.SNITerminate();
     }
     handle = IntPtr.Zero;
     return(true);
 }
Пример #6
0
        // creates a physical connection
        public SniNativeHandle(string serverName, int timeoutSec, out byte[] instanceName) : base(IntPtr.Zero, true)
        {
            timeoutSec = 30;
            var myInfo = new SniNativeMethodWrapper.ConsumerInfo {
                defaultBufferSize = 8000
            };

            SpnBuffer = new byte[SniNativeMethodWrapper.SniMaxComposedSpnLength];
            var timeoutmSec = timeoutSec * 1000;

            instanceName = new byte[256]; // Size as specified by netlibs.

            Status = SniNativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref handle, SpnBuffer, instanceName, false, false, timeoutmSec, false);
        }
Пример #7
0
 public void FlushBuffer(byte[] writeBuffer, int count)
 {
     GetBytesString("Write-", writeBuffer, count);
     if (_writePacket != null)
     {
         SniNativeMethodWrapper.SNIPacketReset(_sniNativeHandle, SniNativeMethodWrapper.IOType.WRITE, _writePacket, SniNativeMethodWrapper.ConsumerNumber.SNI_Consumer_SNI);
     }
     else
     {
         _writePacket = new SniPacket(_sniNativeHandle);
     }
     SniNativeMethodWrapper.SNIPacketSetData(_writePacket, writeBuffer, count);
     SniNativeMethodWrapper.SNIWritePacket(_sniNativeHandle, _writePacket, true);
 }
Пример #8
0
        public int Receive(byte[] readBuffer, int offset, int count)
        {
            var readPacketPtr = IntPtr.Zero;
            var error         = SniNativeMethodWrapper.SNIReadSyncOverAsync(_sniNativeHandle, ref readPacketPtr, 15000);

            if (error != TdsEnums.SNI_SUCCESS)
            {
                SniNativeMethodWrapper.SNIGetLastError(out var errorStruct);
                throw new Exception(errorStruct.errorMessage);
            }

            var dataSize = (uint)count;

            SniNativeMethodWrapper.SNIPacketGetData(readPacketPtr, readBuffer, ref dataSize);
            GetBytesString("Read- ", readBuffer, (int)dataSize);
            SniNativeMethodWrapper.SNIPacketRelease(readPacketPtr);
            return((int)dataSize);
        }