Hi all
Please can anyone help me...
I am getting this error.I am working on a windows application and when I am uploading the file
first time it uploads perfectly but when I upload the same file the upload fails and throws me this exception:
"
"Violation of UNIQUE KEY constraint 'UniqueVisit'.
Cannot insert duplicate key in object 'dbo.Visit\r\nThe statement has been terminated.
\r\nThe 'Visit_Insert'
procedure attempted to return a status of NULL, which is not allow...
Please can anyone advice me on this I tried but not able to fix the issue.
Here is my table
CREATE TABLE [dbo].[Visit](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[VerId] [bigint] NULL,
[ClientId] [bigint] NOT NULL,
[VisitDate] [datetime] NOT NULL,
[VisitId] [char](10) NULL,
[Child] [nvarchar](50) NULL,
[CurrentMeth] [nvarchar](50) NULL,
[FollUp] [nvarchar](50) NULL,
[GestAge] [nvarchar](50) NULL,
[MedicalRef] [nvarchar](50) NULL,
[Sensitive] [nvarchar](50) NULL,
[MarketingRef] [nvarchar](50) NULL,
[Category] [nvarchar](50) NULL,
CONSTRAINT [aaclientTransaction_PK] PRIMARY KEY NONCLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UniqueVisit] UNIQUE NONCLUSTERED
(
[ClientId] ASC,
[VisitId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Visit] WITH NOCHECK ADD CONSTRAINT [FK_clientTransactions_Client] FOREIGN KEY([ClientId])
REFERENCES [dbo].[Client] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Visit] NOCHECK CONSTRAINT [FK_clientTransactions_Client]
GO
ALTER TABLE [dbo].[Visit] WITH NOCHECK ADD CONSTRAINT [FK_ServicePointStatistic_Version] FOREIGN KEY([VersionId])
REFERENCES [dbo].[Version] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Visit] CHECK CONSTRAINT [FK_ServicePointStatistics_Version]
Stored Procedure to insert
ALTER Procedure [dbo].[Visit_Insert]
@VerId bigint,
@ClientId bigint,
@VisitDate datetime,
@VisitId char(10),
@Child nvarchar(50),
@CurrentMeth nvarchar(50),
@FollUp nvarchar(50),
@GestAge nvarchar(50),
@MedicalRef nvarchar(50),
@Sensitive nvarchar(50),
@MarketingRef nvarchar(50),
@Category nvarchar(50),
@Id bigint OUTPUT
AS
insert into Visit
(VerId,
ClientId,
VisitDate,
VisitId,
Child,
CurrentMeth,
FollUp,
GestAge,
MedicalRef,
Sensitive,
MarketingRef,
Category)
values
(@VerId,
@ClientId,
@VisitDate,
@VisitId,
@Child,
@CurrentMeth,
@FollUp,
@GestAge,
@MedicalRef,
@Sensitive,
@MarketingRef,
@Category)
SET @Id = @@IDENTITY
RETURN @Id
Thanks