SQL Server principal cannot access the database under the current security context

Source: Internet
Author: User
using SQL Server today, I found a problem with the INSERT into database name. dbo. Table name (field) values (values) When this statement returns an error: SQL Server Principal The database cannot be accessed under the current security context.

So I looked up the information on the Internet and found it because the Trustworthy database property is used to indicate whether the SQL Server instance trusts the database and its contents. By default, this setting is OFF, but you can use the ALTER DATABASE statement to set it to on.

To see which databases have the trustworthy attribute open, the command is as follows:SELECT name, database_id, is_trustworthy_on from sys.databases, the default is msdb open.

To open the database trustworthy property, the command is as follows:

ALTER database name SET trustworthy on

Authorized user access, the command is as follows:

ALTER AUTHORIZATION on database:: Database name to [user name]

SQL Server principal cannot access the database under the current security context

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.