1

I have a C# console application trying to connect to SQL Teradata using TdConnection class. Below is my code:

using (TdConnection conn = new TdConnection(connstr))
{
    using (TdCommand tdCmd = new TdCommand(selectQry))
    {
        using (TdDataAdapter adptr = new TdDataAdapter())
        {
            conn.Open();
            tdCmd.Connection = conn;
            tdCmd.CommandType = CommandType.Text;
            adptr.SelectCommand = tdCmd;
            tdCmd.CommandTimeout = 30;
            adptr.Fill(dtTechnicianData);
            conn.Close();
        }
    }
}

It was working with Target Framework .Net 5. Recently when Target Framework was changed to .Net 6 for my project, I observed below error @ conn.Open();

System.ObjectDisposedException
  HResult=0x80131622
  Message=Safe handle has been closed.
Object name: 'SafeHandle'.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
   at Interop.Kernel32.SetEvent(SafeWaitHandle handle)
   at System.Threading.EventWaitHandle.Set()
   at System.Threading.ManualResetEventSlim.Set(Boolean duringCancellation)
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute)
   at System.Threading.Tasks.Task.TrySetException(Object exceptionObject)
   at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.InvokeContinuation(Action`1 continuation, Object state, Boolean forceAsync, Boolean requiresExecutionContextFlow)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs _)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompletedInternal()
   at System.Net.Sockets.SocketAsyncEventArgs.HandleCompletionPortCallbackError(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Net.Sockets.SocketAsyncEventArgs.<>c.<.cctor>b__179_0(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading.ThreadPoolBoundHandleOverlapped.CompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pNativeOverlapped)
  • Usually these type errors are due to the connection string being wrong. – jdweng Mar 15 '22 at 13:53
  • It was working with target framework .Net 5. Recently when changed to .Net 6, this issue was observed. – Yograj Varsolkar Mar 15 '22 at 14:31
  • The error says conn.Open() which usually is the connection string. – jdweng Mar 15 '22 at 15:00
  • Ran into the same problem. This appears to be an issue with .NET 6 and the Teradata package. We switched our project back to .NET Core 3.1 to get around this issue. – VolatileCoder Apr 07 '22 at 13:23
  • A Teradata employee posted an answer, now deleted. Quoting: "The fix for .NET runtime will be in .NET 7. A workaround for .NET 6 should be in the next release of the .NET Data Provider for Teradata (coming soon)". Relevant: https://github.com/dotnet/runtime/pull/64627 – Hans Passant May 26 '22 at 20:08

0 Answers0