TableAdapter, Stored Procedure, Uniqueidentifier & Sync Framework Problem

I have a SQL Server Express database which I need to synchronize with two or more occasionally connected computers. The primary keys in all but one of the tables is a uniqueidentifier. I have set one foreign key constraint and one relation. The parent-child form works well until I try to insert a new record. Then I get an error because the newid() default on the uniqueidentifier field doesn't seem to work properly. I have found a work around (on E-E) using stored procedures with the tableadapter. Unfortunately, the wizard option for generating stored procedures is either grayed out or does not exist, depending on how I go about trying to modify (or create) the tableadapter. So --

1. How does one add the stored procedure to a tableadapter? If I create the stored procedures on the server version, will they synchronize to the replica (or vice-versa) or must I create them separately on the two databases?
2. Is there something special to do with child tables?
3. If I can't do it with stored procedures, is there a better way? I have tried generating a new GUID to insert into the detail view textbox but haven't gotten it to work. I have not tried generating a new GUID for the datagridview column which is the next challenge.
LVL 1
rkulpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rkulpAuthor Commented:
I have found a way to generate a new GUID and insert it in the record by trapping the save event. However, I would still like to know how to do the stored procedures with the tableadapter.
0
waheebcCommented:
Is the newID that you are creating a sequince id or autonumber.
If yes then you will have to refresh your databale with the latest data everytime you create a new id
0
rkulpAuthor Commented:
It is a uniqueidentifier and I will refresh the datatable each time. Thanks for your response. Do you have any comments about getting a stored procedure associated with the tableadapter?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rkulpAuthor Commented:
waheebc,

Thanks for the link. This works fine for a selection query. Is there a way to attach a stored procedure that inserts a row where the uniqueidentifier is not a parameter in the stored procedure but is declared and used in the insert query as shown below:


CREATE PROCEDURE dbo.StoredProcedure2 @Provider nvarchar(30)

AS
	/* SET NOCOUNT ON */
	DECLARE @ID uniqueidentifier
	SET @ID = newid()

	INSERT INTO Provider (ID,Provider) VALUES  (@ID,@Provider)
	RETURN

Open in new window

0
rkulpAuthor Commented:
waheebc,

I failed to mention that the tableadapter wizard does not support the DECLARE statement so I can't generate a new stored procedure containing that command and cannot attach an existing stored procedure like the one above. Thus I have to intercept the save command and insert the uniqueidentifier into the dataset or do all inserts using SQL commands. Either way, I have to refresh the datatable.
0
rkulpAuthor Commented:
Unfortunately, it does not solve the insert problem but my work around seems to work fine. Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.