我有一个使用SQL Server作为数据库的应用程序。
有时,客户遇到错误:
timeout expired. the timeout period elapsed prior to completion or the server is not responding
发生此错误时,CPU和网络使用率将达到100%和5mps。
仅当insert
新行和ExecuteScalar
时才会出现此错误
这是我在C#代码中使用的存储过程:
USE [Transportation]
GO
/****** Object: StoredProcedure [dbo].[Shipment_Insert] ScriptDate: 11/23/2017 11:11:45 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Shipment_Insert]
@ReceiptDate date,
@CustomerKey int,
@ShipmentPackage int,
@PortKey int,
@ShipmentType nchar(1),
@ExtOtherType varchar(1),
@GateID int,
@InvoiceNo varchar(50),
@BillNo varchar(50),
@ContractNo varchar(50),
@Package varchar(50),
@CBM varchar(50),
@GW varchar(50),
@Container20 varchar(50),
@Container40 varchar(50),
@Container40HQ varchar(50),
@Container45 varchar(50),
@GoodsName varchar(100),
@Notes ntext,
@CreatedBy nvarchar(50),
@Thanhtoan nvarchar(50),
@ReceivePlace nvarchar(256),
@DeliveryPlace nvarchar(256),
@CargoReceiveDate date,
@CargoDeliveryDate date,
@EmailSubject nvarchar(512),
@TruckingFee nvarchar(50)
AS
DECLARE @ShipmentID nvarchar(50)
DECLARE @CustomerID nvarchar(50)
DECLARE @PortID nvarchar(50)
IF(@CustomerKey > 0)
SELECT @CustomerID = CustomerID FROM CRM_Customers WHERE CustomerKey = @CustomerKey
ELSE
SET @CustomerID = '000'
IF(@PortKey > 0)
SELECT @PortID = PortID FROM SYS_Ports WHERE PortKey = @PortKey
ELSE
SET @PortID = '000'
SELECT @ShipmentID = dbo.AutoGetShipmentID(@CustomerID,@PortID,@ShipmentType,@ReceiptDate,@Thanhtoan, @ShipmentPackage)
--fix end with "/"
IF(RIGHT(@ShipmentID, 1) = '/')
SET @ShipmentID = LEFT(@ShipmentID, LEN(@ShipmentID) - 1)
--
INSERT INTO LGT_Shipments
([ShipmentID],[ReceiptDate] ,[CustomerKey], [ShipmentPackage], [ExtOtherType],[PortKey],[ShipmentType],[EmployeeAppliedKey],[GateID] ,[Status],[InvoiceNo] ,[BillNo] ,[ContractNo] ,[Package] ,[CBM] ,[GW] ,[Container20] ,[Container40] , [Container40HQ] ,[Container45] ,[GoodsName] ,
[Notes],[CreatedBy],[ModifiedBy],[Vehicles],[ConfirmFinish],[FinishToFee],[DebtEmployee],[ProfileEmployee],[GetCustomNo],[Debt],[CustomQuantity], [ReceivePlace], [DeliveryPlace], [CargoReceiveDate], [CargoDeliveryDate], [EmailSubject], [TruckingFee])
VALUES
(@ShipmentID,@ReceiptDate,@CustomerKey,@ShipmentPackage, @ExtOtherType, @PortKey,@ShipmentType,0,@GateID,1,@InvoiceNo ,@BillNo ,@ContractNo ,@Package ,@CBM ,@GW ,@Container20 ,@Container40 ,@Container40HQ ,@Container45 , @GoodsName ,
@Notes,@CreatedBy,@CreatedBy,0,0,0,0,0,0,0,0, @ReceivePlace, @DeliveryPlace, @CargoReceiveDate, @CargoDeliveryDate, @EmailSubject, @TruckingFee)
SELECT @ShipmentID;
我试图在客户端应用程序中增加命令超时,并且sql server超时但没有运气。