Showing posts with label unique. Show all posts
Showing posts with label unique. Show all posts

Wednesday, March 28, 2012

Relationship to UserId

Hi there everyone, this is my first post so go easy on me :)

Basically I am trying to get my database to copy the value in the UserId (unique identifier field) from the aspnet_Users table to a foreign key UserId in a table called userclassset. I have made this field the same datatype and created a relationship between the two. Unfortunately, when I add a user using the ASP.Net configuration tool it does not automatically copy this value into my own custom table. I have noticed it is however automatically copied into the aspnet_Membership table. Any pointers on how to solve this would be great!

Thanks :)

ascension:

?I have noticed it is however automatically copied into the aspnet_Membership table. Any pointers on how to solve this would be great!

This is because when you?use?.NET2.0?built-in?function?to create user,?the?aspnet_Users_CreateUser?stored?procedure?is?called.?This?stored?procedure?will?not?only?insert?a?row?in?aspnet_users?table,?but?also?do?some?operations?on?aspnet_Memebership?table,?you?can?use?sp_helptext?to?view?the?definition:

sp_helptext aspnet_Users_CreateUser

So if you want to insert some row into your own custom table, you can either: alter the aspnet_Users_CreateUser to add your own statements (preferred); orcreate a?insert trigger?on?the?aspnet_users?table|||Brilliant, worked perfectly. Thanks :)

Friday, March 23, 2012

Rejected Inserts: but key unique

I'm getting some records coming up in the conflict viewer which havn't been
inserted because there is a "Violation of the Unique key constraint". But if
I join the conflict table to the target table on the primary key I get no
result so keyfld in the conflict table is unique. Can anyone explain why it
is being rejected?
all the best
spike
Perhaps there is a unique index or unique constraint that is being voilated,
reather than the PK?
Rgds,
Paul Ibison
|||On Apr 30, 2:50 am, Spike <S...@.discussions.microsoft.com> wrote:
> I'm getting some records coming up in the conflict viewer which havn't been
> inserted because there is a "Violation of the Unique key constraint". But if
> I join the conflict table to the target table on the primary key I get no
> result so keyfld in the conflict table is unique. Can anyone explain why it
> is being rejected?
> all the best
> spike
I've seen this with merge replication in SQL 2005 with client pull
subscriptions, Scenario:
1) Publisher has master record "A" and detail records "1,2" with
foreign key constraint applied
2) Subscriber connects, receives master/detail data, disconnects
3) Publisher side deletes master record "A"
4) Subscriber {disconnected} adds detail records "3,4" for master
"A" {succeeds}
5) Subscriber replicates
This is what happens:
1) Master record "A" delete is processed without conflict
2) A compensating master "A" delete is sent to the subscriber - the
master record is removed from the subscription database
3) Detail record "3,4" inserts are sent up to publisher - they fail
with foreign key constraint error
4) Detail records "3,4" remain orphaned in the subscriber database -
each subsequent attempt to replicate generates a new insert/FK
constraint error - overwriting the old one - and the conflict date/
time is updated
Reinitializing the subscriber will remove the orphaned data from the
subscriber database and you should stop seeing the conflict date/time
update with subsequent replication attempts...