简体   繁体   中英

The SELECT permission was denied on the object 'Notes', database 'Sticky', schema 'dbo'

It appears here:

            SyncAdapter notesSyncAdapter = notesBuilder.ToSyncAdapter();
        ((SqlParameter)notesSyncAdapter.SelectIncrementalInsertsCommand.Parameters["@sync_last_received_anchor"]).DbType = System.Data.DbType.Binary;
        ((SqlParameter)notesSyncAdapter.SelectIncrementalInsertsCommand.Parameters["@sync_new_received_anchor"]).DbType = System.Data.DbType.Binary;

The user has has all permissions on both the table, schema and the database. Any idea what might this still throw this exception?

more details: SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();

builder["Data source"] = "achernar"; builder["User ID"] = "sbbf974"; builder["Password"] = "whatever"; builder["Integrated Security"] = false; builder["Initial Catalog"] = "sticky";

The issue was with the user, as Abe guessed. The user was dbo, meaning that although it should have had all the permissions, it didn't. So what I've done was to create another login, to which I gave the following database roles: public, db_datareader, db_datawriter. It works now.

Are you absolutely positive that your code and database are synced up correctly? If you can i'd recommend having one of your coworkers check the following. Sometimes a fresh set of eyes can catch something you've been overlooking...

  • Are you referring to the correct DB in your code (as opposed to a development DB)
  • Are you connecting as the user you think in your code
  • Does that user have permissions in the DB you are connecting to

I know it probably sounds obvious but I'd say it's worth having someone else double check for you. I know I've been caught by this before...

Who is the 'user' ? I much rather trust SQL Server that clearly states that current connection does not have permission. The sync framework goes through several layers, via IIS and ISAPI until it reaches the database, so you better figure out exactly what credentials are used. Is there impersonation at IIS layer occurring? Constrained Delegation? Does the sync framework client authenticate with IIS using what (NTLM/Digest/Basic/Nothing) ?

Try deleting

Trusted_Connection=True;

or

Integrated Security=True;

from your C# code's connection string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM