DTS Integrity Violation

Jun 12, 2000

I having a problem importing a text file into an existing table using the DTS import wizard. The problem I am having is, I am getting an error message stating: Integrity violation: attempt to insert null data or data which violates constraints. The column the error is referenced to is an identity field and I am not trying to insert any data into the field. I have the allow insert identity box checked in the transformation section. Does anyone know about how to solve this problem.
Thanks
James

View 1 Replies


ADVERTISEMENT

Client Agent Error: Integrity Violation

Mar 16, 2006

Hello:

I tried to do the merge replication between SQL 2000 database and the SQL mobile server on PDA with SQL server management studio from SQL 2005 and I have already successfully synchronized my PDA with one small SQL server database file. However when I tried to synchronized my PDA with another larger SQL server database file, I got the error on PDA as following: €œThe row operation cannot be reapplied due to an integrity violation. Check the publication filter. [Table = AuditCriterion, operation = Insert, RowGuid = {1ee9321d-f00d-410c-8d5b-08d4220d2627}]€?. I have keep checking the size of sdf file during synchronization, I found after the size of the sdf file stop increasing for about 20 mintues, then I got the error above. Morever, AuditCriterion table have a foreign key with another table AuditElement and I have not used publication filter at this stage.

Please help thanks.

Eddie

View 1 Replies View Related

Referential Integrity Constraints W/o Referential Integrity In The Db?

Mar 16, 2007

Using the new referential integrity constraints that will be made available, will it allow us to manually define the relationships between entities even if there is no true foreign key constraints setup in the database?

Lets say we deleted the FK_Orders_Customers in Northwind between orders and customers.

Or is this ability available now?

Thank for your time.

View 2 Replies View Related

Access Violation

Aug 22, 2001

How execption access violation error msg with severity 19 handled in sql7 ?

Thanks for info.

View 1 Replies View Related

Primary Key Violation When There Is Only One Row

Feb 23, 2000

I have a table with 5 columns .Length of the 2nd column is 4 characters.
I have to create a new database and copy the existing data.Alter the 2nd column to have 6 charactrers.
Append the values in 2nd column with 00.
I have only one row in the old database.
I am able to copy the rows.But after that when I try to update,it is giving primary key violation error.
What could be the reason?

View 1 Replies View Related

Access Violation

Oct 15, 2003

System Spec: OS = Windows 2000, SQL Server 7 SP4.

I'm getting the following error when I run a stored procedure which truncates a table then inserts data into it. There are no complex joins, order, group by or union clauses in the insert statement:

Error: 0, Severity: 19, State: 0
SqlDumpExceptionHandler: Process 17 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process.

I've read that this is fixed in SQL 7 SP2 but we're on SP4?? I have re-installed SQL SP4.

View 1 Replies View Related

Primary Key Violation ???????

Apr 8, 1999

I am running SQL 6.5 service pack 5a.

I keep getting a Attempt to insert duplicate key row in object... when I try to add a record. I know for a fact that the primary key is not being duplicated because I can look in the db and see that it is not there and if I continue to try to add it it will eventually succeed. Does anyone know what might be causing this?

Please email as well as post.

Thanks.
Carole

View 2 Replies View Related

Primary Key Violation

Jul 14, 2004

Hi,
I have got a very peculier kind of problem. My package is running on SQL 2000. There is a identity primary key in a table. Now when I submit the data from 2 different computer at the same time. Only one data is storing. The reason behind this is the primary key violation. as both the data are sending the request to the database at the same time.................n as the primary key is th identity column, it is storing one that value which is able to store the data at the forst hand.
Now plz help me out in this regard................. :confused:

View 11 Replies View Related

Anticipated PK Violation

Sep 6, 2004

I am maintaining a stored proc that does the following (pseudo code for simplicity)


INSERT INTO MyTable (CountColumn, ...) VALUES (1, ...)

-- 2627 = Primary key violation
IF (@@ERROR = 2627)
UPDATE MyTable SET CountColumn = CountColumn + 1
WHERE ...


Basically, try to create a new record with a PK and a count of 1. If a PK violation occurs, UPDATE the count of existing record.

Pretty simple logic. On some servers this works exactly as expected; the PK violation is caught and handled internally. On other servers, this error percolates out of the stored proc and causes the calling code to receive an error and fail. All servers are SQL Server 2000 SP3a Standard Edition. Any ideas why this happens?

Is there a better (and ideally as fast or faster) way to handle the INSERT/UPDATE issue? I can put the UPDATE first and INSERT if @@ROWCOUNT is 0, but that has the slight potential of a race condition where two processes try to INSERT the same PK at the same time.

View 5 Replies View Related

Violation Of Primary Key

Mar 30, 2008

Violation of PRIMARY KEY constraint 'PK_CUSTOM2'. Cannot insertduplicate key in object 'MHGROUP.Custom2'Is there ANY other reason this violation of the primary key wouldhappen OTHER than a trying to insert a duplicate record?This sql statement false due to the primary key violation:Insert Into MHGROUP.Custom2SelectClientNumber,MatterNumber,MatterDescription,'Y'From MG_EliteMatters EMLeft Outer Join MHGROUP.Custom2 C2On C2.CPARENT_ALIAS = EM.ClientNumberAnd C2.Custom_ALIAS = EM.MatterNumberWhere CPARENT_ALIAS Is Null And Custom_ALIAS Is Null---Custom2CREATE TABLE [MHGROUP].[CUSTOM2]([CPARENT_ALIAS] [varchar](32) COLLATE SQL_Latin1_General_CP1_CI_ASNOT NULL,[CUSTOM_ALIAS] [varchar](32) COLLATE SQL_Latin1_General_CP1_CI_AS NOTNULL,[C_DESCRIPT] [varchar](254) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[ENABLED] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,CONSTRAINT [PK_CUSTOM2] PRIMARY KEY CLUSTERED([CPARENT_ALIAS] ASC,[CUSTOM_ALIAS] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]--MG_EliteMattersCREATE TABLE [dbo].[MG_EliteMatters]([Matters] [varchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[ClientNumber] [varchar](32) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[ClientDescription] [varchar](254) COLLATESQL_Latin1_General_CP1_CI_AS NULL,[MatterNumber] [varchar](32) COLLATE SQL_Latin1_General_CP1_CI_ASNULL,[MatterDescription] [varchar](254) COLLATESQL_Latin1_General_CP1_CI_AS NULL,[LastDateModified] [datetime] NULL,[PracticeArea] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_ASNULL) ON [PRIMARY]

View 1 Replies View Related

Key Violation During Synchronization

Sep 10, 2006

Dear Friends

I restored same database in Publisher & subscriber.If I want to apply Transactional replication I have to apply initial snapshot.then I am getting key-violation problems during initialization .Some times Primary key table will be dropped before foreign key table.sometimes it won't able to drop some indexes.This I am getting if I am going for all tables of database.But here i need all tables.If I am going for selective table I don't have any problem.For avoiding this problem I tried all the options in table article option in publication wizard.But some na some key violation I am getting always.So please give me some better suggestion

Thanks in Advance

Filson

View 5 Replies View Related

Violation Of PRIMARY KEY

Sep 14, 2007

Jobs run at 1 am , sometimes fail with following error.

Violation of PRIMARY KEY constraint 'PK__xxxxx__300424B4'. Cannot insert duplicate key in object 'VW_xxxx . [SQLSTATE 23000] (Error 2627) The statement has been terminated. [SQLSTATE 01000] (Error 3621). The step failed.

when I am reruning 7 am job run successfully. Any advice will be great.

Thanks

View 11 Replies View Related

Primary Key Violation

Oct 7, 2006

Dear Friends,
I am a DBA and I am getting a lot of table locks due to unhandled errors in front-end developed by Power Builder, 5 years back. The backend is SQL Server 2000 Enterprise edition. Below I will explain the problem in detail.

The Big Problem.
{
Ø Users enter sales data into rm_salehdr (docid,..,..,..) table (LOCKED)
Ø The rm_salehdr table need a new docid
Ø The new docid will be generated by a function called as docnogen
Ø The docnogen function
o will select the last docid from ps_docno table
o add 1 to last value
o return docid to rm_salehdr
o update the last docid with the new value.
o ps_docno table will hold the lock till the insert transaction of rm_salehdr will saved. (LOCKED)
Ø If insert into rm_salehdr commit then the insert into ps_docno will be commit. (LOCK Released)
Ø If insert into rm_salehdr rolled back then insert into ps_docno will be rolled back.
Ø (LOCK Released)

}

The Bigger Problem
{
Ø At the same time if another spid select the last docno and completes it transaction before the first transaction then Primary key Violation will arise.
Ø While inserting into rm_salehdr if a user get a error due to primary key violation then user will popped up with a message box explaining the primary key violation error.
Ø If the user does not click the OK button then the transaction will not be ended and LOCK on the table will not released from rm_salehdr.
Ø The LOCK on ps_docno will also be continued.
}

The Biggest Problem
{

Ø My client doesn€™t want to modify the front-end, it is very expensive for them and deployment to remote site is also a problem for them.
Ø They want me to handle it from the backend.
}


Is it possible that to handle the error message and release the lock on rm_salehdr from backend.

Commit the data first in ps_docno so lock will be released
I want your valuable suggestions and advice.

Thanks in advance.
Regards,
Raj



View 4 Replies View Related

Do I Need More Integrity On My DB?

Jul 5, 2004

I am not sure I need more integrity on my DB. My DDL are down below.
thanks

************************************************** *****

create table person(
personId int identity(1,1) primary key,
fName varchar(25) not null,
mI char(1) null,
lName varchar(25) not null
);


create table student(
studentId char(4) not null primary key,
personId int not null
);


alter table student
add constraint fk_person_student
foreign key (personId)
references person (personId)
;

create table instructor(
instructorId char(4) not null primary key,
instructorQual varchar(100) not null,
personId int not null
);

alter table instructor
add constraint fk_person_instructor
foreign key (personId)
references person (personId)
;

create table contract(
contractNum int identity(1,1) primary key,
contractDate smalldatetime not null,
tuition money not null,
studentId char(4) not null foreign key references student (studentId),
contactId int not null foreign key references contact (contactId)
);

create table contact(
contactId int not null primary key,
fName varchar(25) not null,
mI char(1) null,
lName varchar(25) not null,
street varchar(50) not null,
city varchar(25) not null,
state char(2) not null,
zip char(5) not null,
relationship varchar(25) not null,
phNum char(12) not null,
emailAdd varchar(50) null,
);

create table class(
classNum char(4) not null primary key,
className varchar(25) not null,
classDay char(3) not null,
classTime char(8) not null,
testNum char(5) not null
);


alter table class
add constraint fk_class_testnum
foreign key (testNum)
references test (testNum)
;

create table discount(
discountNum char(3) primary key,
discountDesc varchar(100) not null,
discountPer decimal(3,2) not null
);

create table test(
testNum char(5) primary key,
testName varchar(50) not null,
testDate smalldatetime not null,
testFee money not null,
);

create table studentClass(
studentId char(4) not null,
classNum char(4) not null,
pass char(1) not null
);

alter table studentClass
add constraint pk_studentclass primary key clustered (studentId, classNum)
;


alter table studentClass
add constraint fk_studentclass_studenttid
foreign key (studentId)
references student(studentId)
;

alter table studentClass
add constraint fk_studentclass_classnum
foreign key (classNum)
references class(classNum)
;

create table contractDiscount(
contractNum int not null,
discountNum char(3) not null
);

alter table contractDiscount
add constraint pk_contractdiscount primary key clustered (contractNum, discountNum)
;

alter table contractDiscount
add constraint fk_contractdiscount_contractnum
foreign key (contractNum)
references contract(contractNum)
;

alter table contractDiscount
add constraint fk_contractdiscount_discountnum
foreign key (discountNum)
references discount(discountNum)
;

create table instructorClass(
instructorId char(4) not null,
classNum char(4) not null,
);


alter table instructorClass
add constraint pk_instructorclass primary key clustered (instructorId, classNum)
;

alter table instructorClass
add constraint fk_instructorclass_instructorid
foreign key (instructorId)
references instructor(instructorId)
;

alter table instructorClass
add constraint fk_instructorclass_classnum
foreign key (classnum)
references class(classnum)
;

View 2 Replies View Related

MDF Integrity

Jun 8, 2007

Hi all,



Is there any way to check the integrity of .Mdf file before attaching it to a database means to check whether its valid (or) not.



Thanks.



//Najeed

View 2 Replies View Related

Violation Of PRIMARY KEY Constraint

Mar 23, 2005

Hi,
I am trying to insert into a table. I got the above error message then I deleted all the data in the table. But I am still getting this error.

Whats wrong?

View 2 Replies View Related

Violation Of Primary Key Error

Dec 13, 2005

hi,
I am trying to save the record which is displayed in the textbox by selecting a row in the datagrid. If i click the save button I am getting the following error.
Violation of PRIMARY KEY constraint 'PK_clientinfo'. Cannot insert duplicate key in object 'clientinfo'. The statement has been terminated.      
button save-----------
    conn.Open();    SqlCommand cmd = new SqlCommand("insert into clientinfo (client_name, address, telephone, fax, email, contperson1, dept, contpos1, contperson2, contpos2, rscompname, rscontperson, rsposition, actdate, acttime, instsno, actkey) values ('"+txtclientname.Text+"', '"+txtaddress.Text+"', '"+txttelephone.Text+"', '"+txtfax.Text+"', '"+txtemail.Text+"', '"+txtcntperson1.Text+"', '"+txtdept.Text+"', '"+txtcnt1pos.Text+"', '"+txtcntperson2.Text+"', '"+txtcnt2pos.Text+"', '"+txtcompname.Text+"', '"+txtrscntperson.Text+"', '"+txtrspos.Text+"', '"+txtactdate.Text+"', '"+txtacttime.Text+"','"+txtinstno.Text+"', '"+txtactkey.Text+"')", conn);    cmd.ExecuteNonQuery();    conn.Close();    BindData();    txtclear();       } 

View 1 Replies View Related

Concurrency Violation Error!

May 16, 2006

Hiim keep getting  the following errorConcurrency violation: the UpdateCommand affected 0 recordsI dunno whats wrong, im the only person using the database and program at the moment.Anyone know what im doing wrong?thanks 

View 1 Replies View Related

Access Violation In Sql Server

Sep 22, 2000

Hi,
I received this event in my eventlog

Error: 0, Severity: 19, State: 0
SqlDumpExceptionHandler: Process 6 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process.

What could be the cause of this??

Thanks in advance
Mikael

View 3 Replies View Related

ERROR MSG: Violation Of PRIMARY KEY

Apr 30, 1999

Hi,

On a regular basis, it seems that the primary key of my table gets corrupted and I get the error message below. I can still read the data but no longer update or insert.
There is no reason why there should be such error. I fix it by creating a temporary table and copying the data accross, then renaming the
table, but I would rather prevent it. Any thought on this??


<P>ODBC Error Code = 23000 (Integrity constraint violation)
<P>[Microsoft][ODBC SQL Server Driver][SQL Server]Violation of PRIMARY KEY
constraint 'PK___1__23': Attempt to insert duplicate key in object 'SiteList'

View 1 Replies View Related

How Do You Find A Primary Key Violation

Jan 11, 2005

I need to find out which record I am violating by trying to execute this stored procedure

ALTER PROCEDURE InsertCorovan2004
AS
INSERT INTO [GamingCommissiondb].[dbo].[Corovan_Table]
([TM #],
[FirstName],
[LastName],
[SS #],
[TerminationDate],
[Voluntary or Involuntary])

SELECT [TM #], FirstName, LastName, SocialSecurityNumber, TerminationDate, VoluntaryorInvoluntary
FROM dbo.TERMINATION
WHERE (TerminationDate BETWEEN CONVERT(DATETIME, '2004-01-31 00:00:00', 102) AND CONVERT(DATETIME, '2004-12-31 00:00:00', 102))

GO



when I execute it I get this error message
Server: Msg 2627, Level 14, State 1, Procedure InsertCorovan2004, Line 3
Violation of PRIMARY KEY constraint 'PK_Corovan_Table'. Cannot insert duplicate key in object 'Corovan_Table'.
The statement has been terminated.
Stored Procedure: GamingCommissiondb.dbo.InsertCorovan2004
Return Code = -4


I am trying to insert 2004 terms into the corovan table from TERMINATION table. How do you find out what records match from each table (compare the tables reocords for dups). How would I do this in the query analyzer since thats mainly what I use. I get a better understanding of how to create proceudure in the query analyzer so I;d rather stick to it.

In short I need to find the Culprit record that is preventing me from insert the 2004 records


Thank you

View 14 Replies View Related

Violation Of PRIMARY KEY Constraint

Sep 21, 2005

I know what this error means is that you can not insert duplicate primary keys in the table but the thing is I am checking the rows if they do not exist then insert otherwise don't do any thing these are the lines I am writing in my strored procedure can someone please let me know what I am doing wrong here.

If not exists
(Select * From GGP WHERE
FFECTIVE_DATE =@v_EFFECTIVE_DATE AND
ASSET_ID= @v_ASSET_ID AND
ASSET_TYPE = @v_ASSET_TYPE AND
Value = @v_Value AND
hour = @v_Hour)

INSERT INTO GGP
(ASSET_ID,ASSET_TYPE,Hour,Value,EFFECTIVE_DATE) values(@v_ASSET_ID,@v_ASSET_TYPE,@v_Hour,@v_Value, @v_EFFECTIVE_DATE)



The exact error is
Violation of PRIMARY KEY constraint 'PK_SP_GGP'. Cannot insert duplicate key in object

Thanks in advance.

View 7 Replies View Related

Violation Of PRIMARY KEY Constraint

Apr 10, 2006

When I try to insert data into a table (let's just call it MyTable for this post), I suddenly get the following error.

Violation of PRIMARY KEY constraint 'PK_MyTable'. Cannot insert duplicate key in object 'MyTable'.

My table does have a primary key field named 'id', which is an auto-incrementing BIGINT. The last record I successfully inserted received 14 in the id field, so I'm assuming the database is trying to assign 15 to the next. Unfortunately, there is already a record with an id of 15; the next available id is 21.

Is there a way to avoid these primary key collisions?

View 5 Replies View Related

Primary Key Violation Error

Apr 8, 2008

Can anyone help me in handling errors I'm trying to update Employee master table, but i get error messege of violating primary-key constraint

View 3 Replies View Related

Violation Of Primary Key Constraint

Mar 3, 2006

I'm trying to insert records into a table and getting the below error and not sure how to resolve it:

Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_propertyItem'. Cannot insert duplicate key in object 'propertyItem'.
The statement has been terminated.

View 2 Replies View Related

Access Violation Problem - Need Help

Jun 18, 2007

I have a task i.e. to make the following query work.
But it shows me syntax error. I dont know what this query is doing and I have no concerns about it. so if any body could help me out that will be a big help :)

SHAPE {

SELECT * FROM Leads
WHERE 1=1
AND ( ([Lead Quality] NOT IN (1,5,6,7) )
AND ( idVendors = '{ADF4406A-ACB7-4610-A03F-702D86CC259F}' )
AND ( idLeads IN (select idleads from [vendors history] where status = 3) )
AND ( [received datetime] between '6/18/2007' AND '6/19/2007' )
AND ( [Lead Type] NOT IN (7,8) )
)
ORDER BY idVendors, [Customer ID]

}
AS [Leads Detail]

APPEND

( { SELECT * FROM [Leads Borrower Information] WHERE [CoBorrower Indicator] = 0 } As [Borrower Information] RELATE 'idLeads' TO 'idLeads'),
( { SELECT * FROM [Leads Borrower Information] WHERE [CoBorrower Indicator] = 1 } AS [CoBorrower Information] RELATE 'idLeads' TO 'idLeads'),
( { SELECT * FROM [Leads Property Information] WHERE [Mailing Address Indicator] = 0 } As [Property Information] RELATE 'idLeads' TO 'idLeads'),
( { SELECT * FROM [Leads Property Information] WHERE [Mailing Address Indicator] = 1 } AS [Mailing Information] RELATE 'idLeads' TO 'idLeads'),
( { SELECT * FROM [Leads Mortgage Information] WHERE [Mortgage Indicator] IN (0,1) } AS [First Mortgage Information] RELATE 'idLeads' TO 'idLeads'),
( { SELECT * FROM [Leads Mortgage Information] WHERE [Mortgage Indicator] = 2 } AS [Second Mortgage Information] RELATE 'idLeads' TO 'idLeads'),
( { SELECT * FROM [Vendors] } As [Vendor Information] RELATE 'idVendors' to 'idVendors'),
( { SELECT * FROM [Lead Quality Reason Values] } As [Return Reason] RELATE 'Lead Quality Reason' to 'Value'),
( { SELECT [Batch ID], idLeads, idVendorsOrders FROM [Vendors History] WHERE STATUS IN (1,2) } As [Vendor History] RELATE 'idLeads' to 'idLeads'),
( { SELECT TOP 1 idLeads, DateTime from [Clients History] WHERE Status IN (3) ORDER BY DateTime ASC } As [Clients History] RELATE 'idLeads' to 'idLeads')

View 3 Replies View Related

VIOLATION OF PRIMARY KEY CONSTRAINT

Feb 15, 2008

Violation of PRIMARY KEY constraint 'PK_tbl_others. Cannot insert duplicate key in object 'tbl_others.
The statement has been terminated.-- What does it mean i cant load the data to tbl_others

View 2 Replies View Related

Violation Of Primary Key Constraint

Apr 2, 2007

When replication merge, is taking place between two servers on one particular table I keep getting violation of primary key constraint, Does anyone out there have a fix for this?

View 1 Replies View Related

'check Constraint' Ignored - PK Violation

Jul 24, 2007

I thought the whole point of 'check constraint' being unticked meant you could whack your data straight in no probs.

How can I insert a bunch of historical information where I want to control the PK, in this case DealID?

I have got 'keep identity' checked.

I check the db, the Id does NOT exist currently.


Error: 0xC0202009 at Data Cleansing, Deal Insert [12194]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "The statement has been terminated.".
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK_DealID'. Cannot insert duplicate key in object 'dbo.Deal'.".

View 3 Replies View Related

Violation Of Primary Key Constraint

Jan 4, 2008

Hi,

I've a set of source tables on one server and a set of destination tables on another.
When I move data from one server to next, I get an error saying "Violation of Primary Key Constraint". This happens for only one table among the 6 tables that I have. I dont understand why it throws me this error. Though theres an error for this table, the data from source table moves into this destination table.

Am I missing something?


Thanks,
Subha Fernando

View 7 Replies View Related

Violation Of Primary Key Constraint

Jan 4, 2008


Hi,

I've a set of source tables on one server and a set of destination tables on another. I'm moving this using a data flow task.
When I move data from one server to next, I get an error saying "Violation of Primary Key Constraint". This happens for only one table among the 6 tables that I have. I dont understand why it throws me this error. Though theres an error for this table, the data from source table moves into this destination table.

Am I missing something?


Thanks,
Subha Fernando

View 5 Replies View Related

InsertCommand.ExecuteNonQuery() And Violation Of PrimaryKey

Jan 15, 2007

Hey,
I have a page that inserts into a customers table in the DataBase a new customer account using this function:
Public Function InsertCustomers(ByRef sessionid, ByVal email, ByVal pass, Optional ByVal fname = "", Optional ByVal lname = "", Optional ByVal company = "", Optional ByVal pobox = "", Optional ByVal add1 = "", Optional ByVal add2 = "", Optional ByVal city = "", Optional ByVal state = "", Optional ByVal postalcode = "", Optional ByVal country = 0, Optional ByVal tel = "")
Dim result As New DataSet
Dim tempid As Integer
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("Conn"))
Dim Adcust As New SqlDataAdapter
Adcust.InsertCommand = New SqlCommand
Adcust.SelectCommand = New SqlCommand
Adcust.InsertCommand.Connection = conn
Adcust.SelectCommand.Connection = conn
sessionExists(email, sessionid, 1)
conn.Open()
If fname = "" Then
Adcust.InsertCommand.CommandText = "Insert Into neelwafu.customers(email,password,sessionid) Values('" & email & "','" & pass & "','" & sessionid & "')"
Else
Dim strsql As String
strsql = "Insert Into neelwafu.customers"
strsql = strsql & "(sessionid,email,password,fname,lname,company,pobox,address,address2,city,state,postalcode,countrycode,tel) values("
strsql = strsql & "'" & sessionid & "','" & email & "','" & pass & "','" & fname & "','" & lname & "','" & company & "','" & pobox & "','" & add1 & "','" & add2 & "','" & city & "','" & state & "','" & postalcode & "', " & country & ",'" & tel & "')"
Adcust.InsertCommand.CommandText = strsql
End If
Adcust.InsertCommand.ExecuteNonQuery()
Adcust.SelectCommand.CommandText = "Select Max(id) from neelwafu.Customers"
tempid = CInt(Adcust.SelectCommand.ExecuteScalar())
conn.Close()
Return tempid
End Function
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Now, I am getting an error:
Violation of PRIMARY KEY constraint 'PK_customers_1'. Cannot insert duplicate key in object 'customers'. The statement has been terminated.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The customers table has as a primary key the 'email'.....
so plz can I know why am I getting this error ????
Thank you in advance
Hiba

View 4 Replies View Related

Capture Primary Key Violation Error

Sep 14, 2007

Hello,,
I need to capture the primary key violation error:
        If e.CommandName = "Insert" Then            Dim EmployeeIDTextBox As TextBox = CType(dvContact.FindControl("EmployeeIDTextBox"), TextBox)            Dim LastName As TextBox = CType(dvContact.FindControl("LastName"), TextBox)            Dim FirstName As TextBox = CType(dvContact.FindControl("FirstName"), TextBox)     
            Using cmdAdd As New System.Data.SqlClient.SqlCommand
                'Establish connection to the database connection                Dim sqlcon As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("eConnString").ToString)
                'Open connection                sqlcon.Open()
                'Pass opened connection (see above) to the command object                cmdAdd.Connection = sqlcon
                'Using "With/End With" pass content to columns from text objects and datatime variables (see above)                With cmdAdd                    .Parameters.Add(New SqlClient.SqlParameter("@EmployeeID", EmployeeIDTextBox.Text))                    .Parameters.Add(New SqlClient.SqlParameter("@LastName", LastName.Text))                    .Parameters.Add(New SqlClient.SqlParameter("@FirstName", FirstName.Text))                              'Establish the type of commandy object                    .CommandType = CommandType.Text
                    'Pass the Update nonquery statement to the commandText object previously instantiated                    .CommandText = "INSERT INTO ATTEmployee(EmployeeID, LastName, FirstName & _                         "VALUES (@EmployeeID, @LastName, @FirstName)"                End With
                'Execute the nonquerry via the command object                cmdAdd.ExecuteNonQuery() '<==Need to capture primaryKey violation, give user message, cancel insert,return to detailView ReadOnly
               'I haven't figured out the correct code to capture the primary key violation
               EDITMsg.Text="You can not insert an duplicate record.  Try Again."
                'Close the sql connection                sqlcon.Close()            End Using        End If
 
Thank you for your help

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved