Need to learn how to set appropriate permissions on SQL Server database to allow Synchronisation through Sync Framework 2.1

梦想与她 提交于 2019-12-11 06:49:43

问题


SQL Server is not my strong point and I start to get lost when going past the basic Create Table, Select from Table etc.

I am attempting to set up a database synchronisation scenario with an Microsoft SQLCompact 3.5 database being Synced through a Proxy to and SQL 2008 R2 database. It is being synced through the Microsoft Sync Framework 2.1.

I got everything set up and working fine through the proxy when the user account is the db_owner of the database.

Of course this now needs to be locked down - so I have been trying to restrict the permissions to the bare minimum required for Synchronisation.

According to the Microsoft articles, I need to do the following...

Use the principle of least permission. Do not grant more permissions than are required to perform a specific task. For example, do not grant INSERT permissions for server database tables that are involved in download-only synchronization. Synchronization operations require the following permissions:

EXECUTE permissions on all the stored procedures that Sync Framework uses to read and write to metadata tables and base tables.

SELECT, INSERT, UPDATE, and DELETE permissions for metadata tables and any base tables that will be updated during a synchronization session.

When you provision SQL Server databases that use SqlSyncProvider, be aware of the following permissions requirements for provisioning:

CREATE TABLE permissions to enable creation of the metadata tables: scope_info and scope_config, and the tracking tables that are created for each base table.

ALTER TABLE to add triggers to the base tables.

CREATE PROCEDURE permissions to create the procedures that Sync Framework requires.

SELECT and INSERT permissions for scope_info and scope_config tables.

SELECT permissions for base tables.

I allowed the wizards in Visual Studio 2010 to create the Sync database and proxy for me.

As such - I am unable to find the scope_info and scope_config tables in SQL Server databases, and I am also unable to find the metadata tables so cannot set permissions on these tables. Also - where would I find the stored procedures that the Synchronisation framework is trying to use - I have looked but cannto find them.

Where would I find these and how would I go about setting the appropriate permissions?

I have granted datareader and datawriter, Insert, Update, Delete and Select as well as Execute permissions on the SQL Server database but the sync fails. I have also granted Create Table, Create Procedure and ALTER permissions on the database for the user as well- but still it fails.

If i enable the db_owner role for the user - it works.

The error I receive is:

Unable to initialize the client database, because the schema for table 'tblApplications, tblApplicationConfiguration, tblApplicationInstallProperties, tblApplicationPreRequisites, tblApplicationTypes, tblComputerApps, tblComputers, tblComputerTypes, tblDriveHWSerials, tblDrives, tblDriveTypes, tblFunctions, tblLocationApps, tblLocationComputers, tblLocationIPAddress, tblLocations, tblLocationUsers, tblPermissions, tblRegionLocations, tblRegions, tblRegisteredModules, tblRequestFormats, tblRequestStatus, tblRequestTypes, tblRoles, tblRoleUsers, tblSecurity, tblUsers, tblVehicle, tblVehicleLocationMap, tblVehicleMake, tblRequestProcessingStatus, tblDriveStatus, tblVideoViewTypes' could not be retrieved by the GetSchema() method of DbServerSyncProvider. Make sure that you can establish a connection to the client database and that either the SelectIncrementalInsertsCommand property or the SelectIncrementalUpdatesCommand property of the SyncAdapter is specified correctly.

I am not able to use the db_owner role when its released.


回答1:


there are two types of database providers in Sync Framework, the offline provider (SqlCeClientSyncProvider/DbServerSyncProvider) which is used by the Local Database Cache project item and the collaboration/peer-to-peer provider (SqlSyncProvider/SqlCeSyncProvider).

the offline providers dont use the scope_xxx tables as such you wont find it.

assuming you used the default SQL Server Change Tracking when you configured the sync via the wizard, try granting VIEW CHANGE TRACKING permission to the account you're using to connect to the database.




回答2:


I'm not sure if it will help, but I found this:

Try to set UploadOnly on the SyncTable object instead. When you set it on the SyncAdapterBuidler, the select incremental commands are not generated by the builder. These commands are used to get the table schema from the database. Since these are missing you are getting the schema error.

Also, maybe this blog entry will help.




回答3:


As JuneT Mentioned, you should turn on Change Tracking

ALTER DATABASE YourDataBaseName  
SET CHANGE_TRACKING = ON  
(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)  


来源:https://stackoverflow.com/questions/8032413/need-to-learn-how-to-set-appropriate-permissions-on-sql-server-database-to-allow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!