简体   繁体   中英

Error: the underlying provider failed on open. system.data.sqlclient.sqlexception login failed for user

After deploying my C# win app in client computer, the following error occurs:

The underlying provider failed on open.system.data.sqlclient.sqlexception

login failed for user. cannot open database "EmdadKhordo" Requested by the login

This is my connection string:

metadata=res://*/Models.EmdadKhodroDB.csdl|res://*/Models.EmdadKhodroDB.ssdl|res://*/Models.EmdadKhodroDB.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=EmdadKhodroDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"

I use Entity Framework to access a SQL Server database.

Based on the cannot access database error message, authentication succeeded to the SQL instance but the specified database cannot be accessed. This may be because the EmdadKhodroDB database does not exist, is not online, or (most likely) inaccessible under the current security context. Make sure the account you are using has access to the database and the needed object permissions.

The DCL below will add the user to the database. You will also need to grant object level permissions directly to the user or a role of which the user belongs.

USE EmdadKhodroDB;
CREATE USER [YourDomain\YourAccount];

You can also manage your Windows user rights using SQL Management Studio . Just follow instructions from here for creating a new login and also configure mappings to each database you need access to.

Basically you need to make sure that your login is properly defined (Security -> Logins) and that it has the appropriate rights on EmdadKhordo database (read, write etc.). The recommendation is to allow the minimum required rights (eg do not allow to alter tables, if only SELECT, INSERT, UPDATE, DELETE statements are performed by the user).

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