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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.
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
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?
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

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:

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)

	DECLARE @ID uniqueidentifier
	SET @ID = newid()

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

Open in new window

rkulpAuthor Commented:

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.
rkulpAuthor Commented:
Unfortunately, it does not solve the insert problem but my work around seems to work fine. Thanks for the help.
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.