Linux下dotnet核心中的MS-SQL通信引发错误

时间:2019-04-23 07:01:23

标签: linux .net-core sqlclient

我在默认端口1433上运行。 当我对数据库执行简单查询时,一切正常。 但是当我尝试运行存储过程时..像这样:

DataTable result = null;

SqlCommand command = new SqlCommand();
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = procedureNameWithDbVersionPrefix;
command.CommandTimeout = m_nTimeout;
foreach (string item in m_Parameters.Keys)
{
    command.Parameters.Add(new SqlParameter(item, m_Parameters[item]));
}
string sConn = GetConnectionString();
using (SqlConnection con = new SqlConnection(sConn))
{
    try
    {
        con.Open();
        command.Connection = con;

        SqlQueryInfo queryInfo = Utils.GetSqlDataMonitor(command);
        using (KMonitor km = new KMonitor(KLogMonitor.Events.eEvent.EVENT_DATABASE, null, null, null, null) { Database = queryInfo.Database, QueryType = queryInfo.QueryType, Table = queryInfo.Table, IsWritable = (m_bIsWritable || Utils.UseWritable).ToString() })
        {
            using (SqlDataReader reader = command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    result = new DataTable();
                    result.Load(reader);
                }
            }
        }

        con.Close();
    }
    catch (Exception ex)
    {
        string sMes = "While running : '" + procedureNameWithDbVersionPrefix + "'\r\n Exception occurred: " + ex.Message;
        log.Error(sMes, ex);
        return null;
    }
}

我仅在Linux系统上遇到此异常。在Windows上运行都正常。 实际上,在Windows上的基于Linux的docker中运行的事件均正常运行.. ::

ERROR 2019-04-23 06:49:53,933 (33) class:ODBCWrapper.StoredProcedure topic:null method:UpdateBulkUpload server:c931619e64e0 ip:null reqid:35a07e86-933a-4f0c-93ec-3428e4d92687 partner:203 action:null uid:770357 msg:While running : '__522v0__UpdateBulkUpload'
 Exception occurred: A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 35 - An internal exception was caught)
System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.IO.IOException: Unable to write data to the transport connection: Operation canceled. ---> System.Net.Sockets.SocketException: Operation canceled
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParserStateObject.SNIWritePacket(Object packet, UInt32& sniError, Boolean canAccumulate, Boolean callerHasConnectionLock)
   at System.Data.SqlClient.TdsParserStateObject.WriteSni(Boolean canAccumulate)
   at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate)
   at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush()
   at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SqlClient.SqlCommand.ExecuteReader()
   at ODBCWrapper.StoredProcedure.Execute(Boolean shouldGoToSlave) in /src/Core/ODBCWrapper/StoredProcedure.cs:line 130

0 个答案:

没有答案