VB.Net programming of SQL Server Replication

The article http://msdn.microsoft.com/en-us/library/ms146869.aspx suggests that Microsoft.SQLServer.Replication.dll is in the .Net references. For me it was not, it could however be found at:
C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies

Also needed:

  1. Microsoft.SQLServer.Rmo
  2. Microsoft.SQLServer.Replication
  3. Microsoft.SQLServer.Replication.BusinessLogicSupport
  4. Microsoft.SQLServer.ConnectionInfo
Advertisements

How do I … work with Guid in ADO.Net?

How do I … work with Guid in ADO.Net?
( in this case to support SQL Server replication using dataset )

26-Dec-2011
Hypothesis: That DataSet could act unaware of replication column (do not import it on datatable creation) (or delete it after). Then use default in SQL Server (newsequentialid())
Experiment: Worked out of the box – straight away

During creation of SQL Replication, SQL Server will add a rowGuid column which is a uniqueidentifier and places a default of (newsequentialid()) onto this column
Insert statements for replication must include all columns, except the rowGuid column.

ERROR
However if you then add a new row to this table in ADO.Net then program will give error message ‘Column rowGuid does not allow nulls’

SOLUTION
[MyDataTable].rowguidColumn.DefaultValue = Guid.NewGuid

EXPLANATION
SQL will have inserted a Unique index on rowGuid. However when the table is dropped onto the dataset the unique key is not there. Therefore although the above default set once will give each new row the same Guid, the ADO.net sees no errors. Because the insert statement does not insert the Guid, SQL does, then ADO.Net immediately returns the correct newly applied Guid from the database. This is because the Dataset insert statement also has a SELECT statement on it to get table updates immediately after the INSERT.

SQL Server Replication

Updating ERROR
Updating columns with the rowguidcol property is not allowed.
The transaction ended in the trigger. The batch has been aborted.

Removed the rowguid column from the dataset update sql and it worked. Found no online instruction for this in short search.

SQL Server Replication

PUBLISHER
SQL Server Agent account must be running on publisher
Snapshot folder must be a UNC folder which is shared

SUBSCRIBER
Agent process account could be Subscriber Computer or Domain name \ User Name
Distributer connection and Publisher connection I used a SQL Authentication account which will already work for normal login

ERROR: On Subsciber
Msg 14058, Level 16, State 1, Procedure sp_addmergesubscription, Line 381
Cannot create the subscription because the subscription already exists in the subscription database. Only one subscription to the same publication is allowed in each subscription database. Drop the subscription and add it again if necessary. If the problem persists, replication metadata might be incorrect; see Books Online for troubleshooting information.

SOLUTION: On Publisher
SELECT * FROM sysmergesubscriptions
DELETE FROM sysmergesubscriptions WHERE subscriber_server = ‘ServerName’

ERROR: On Publisher
Unable to start execution of step 2 (reason: Error authenticating proxy ComputerName\UserName, system error: Logon failure: unknown user name or bad password.).  The step failed.

SOLUTION: On Publisher
Agent Security use a windows account. Password is the windows password for that account.
This account must have at least db_owner for the database being published.
It must also have write permissions on the publication folder.
http://msdn.microsoft.com/en-us/library/ms186515(v=SQL.105).aspx
STATUS: Should now have files on Publisher in Snapshot folder

ERROR: On Subsriber
the schema script ‘….sch’ could not be propagated to the subscriber
Go to subscriber view job history. Message in there may be above plus
‘The process could not read file ‘…\MSSQL\ReplData\unc\…’ due to OS error 3.

SOLUTION: On Publisher
Use a UNC path on the publication. To do this > Publisher > Publication > Right click properties > Snapshot > Put files in the following folder
Then use \\ server or computer name \ .. \ MSSQL \ReplData or which ever folder
Should now work