none
System.Data.SqlClient.SqlException: User does not have permission to perform this action. RRS feed

  • Question

  • I have successfully set up the ASPNETDB.mdf so I can use security on my site within Visual studio Express.  Everything works fine when I run the app from Visual Studio Express.  When I deploy the app to a production server, I get the error below.  I know it is a permissions issue, but I have tried everything I know to try.  I am using SQL Express 2008. How can I fix this problem?  What permission do I need to add or reconfigure?  I am using forms authentication on my website. This error appears after I enter the username and password and click the Log In button on the Login.aspx page. 

    Here is my connection string; Data Source=.\SQLEXPRESS;AttachDbFilename=C:\inetpub\SandyRidgeOldTimers\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True

     

     I really don't know what other information I should provide here so please ask if you need further information and thanks for your help everyone!

     

    Server Error in '/' Application.


    User does not have permission to perform this action.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: User does not have permission to perform this action.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [SqlException (0x80131904): User does not have permission to perform this action.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064474
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +5078123
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
       System.Data.SqlClient.SqlConnection.Open() +125
       System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +95
       System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +206
       System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +827
       System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
       System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +106
       System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) +60
       System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +129
       System.Web.UI.WebControls.Login.AttemptLogin() +127
       System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +125
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +167
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
    



    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237



    • Edited by bcc_net Wednesday, November 30, 2011 4:01 AM
    Wednesday, November 30, 2011 3:56 AM

Answers

  • WOW, after all that messing around and it was as simple as adding this to the web.config:

    <identity impersonate="true" userName="ServerName\login" password="p455w0rd" />

    I did not have the username and password in my original Identity tag.  Hope this helps someone else!

    Thanks again Mohib for working with me!

    • Marked as answer by bcc_net Thursday, December 1, 2011 4:04 AM
    Thursday, December 1, 2011 4:04 AM

All replies

  • I am not sure about the exact cause or solution but in my experience, removing "User Instance=True" from the connection string works most of the time. Also verify the MDF file on production server has access to Everyone in file permissions.

    Life would have been much easier if I had the source-code !!
    Wednesday, November 30, 2011 4:30 AM
  • Removing that did not work and I already set Everyone in file permissions.  I have tried everything with permissions. Everything except the one thing that works that is!  :)

     

    Thanks for your help though. Anyone else?  I am trying to deliver this app by Friday and I am in a bind here so any help is greatly appreciated!

    Wednesday, November 30, 2011 4:36 AM
  • Have you granted permission for the IIS to the sql express engine? Try this.. http://stackoverflow.com/questions/5351365/how-do-i-grant-access-to-my-sql-server-express-database-to-a-specific-user-with


    Life would have been much easier if I had the source-code !!
    Wednesday, November 30, 2011 4:45 AM
  • I don't know how to do what is suggested in that thread.  I am accessing the SQL database from Visual Studio because it is SQL Express.  I don't have Server Management Console Express Edition as they suggested in that thread.  I tried to install it, but it errors out.  I really don't know what to do from here. 

    where exactly do I run these commands?

    CREATE LOGIN [DEV1\IIS AppPools] FROM WINDOWS WITH DEFAULT_DATABASE=[master] 
    GO 
    CREATE USER [DEV1\IIS AppPools] FOR LOGIN [DEV1\IIS AppPools] 
    GO 
    EXEC sp_addrolemember N'db_datareader', N'DEV1\IIS AppPools' 
    GO 
    EXEC sp_addrolemember N'db_datawriter', N'DEV1\IIS AppPools' 
    GO 

    Thanks!

    Wednesday, November 30, 2011 5:36 AM
  • You will need to connect to your database once to grant access to the Product Server User Account. For this, you will need to connect one using SQL Management Studio, or you could execute these commands, on your development PC and then copy the database file to Productin server.
    Life would have been much easier if I had the source-code !!
    • Proposed as answer by Peja Tao Thursday, December 1, 2011 2:04 AM
    Wednesday, November 30, 2011 5:44 AM
  • Thanks for your help, but my question is how do I do what you are suggesting?  Do I do this somewhere inside of Visual Studio Express?  How can I install SQL Management Studio?  When I download it from MS and install, it just throws errors.  

     

    Thanks!

    Wednesday, November 30, 2011 5:52 AM
  • If I try to run this as a query in Visual Studio Express, it errors out.  It says the ASPNETDB database does not exist, but it does.

    CREATE LOGIN [DEV1\IIS AppPools] FROM WINDOWS WITH DEFAULT_DATABASE=[master] 

    What is \IIS App Pools???  This is nothing I have ever done before so if you can guide me with instructions, that would be very helpful. 

    Thanks again!

    Wednesday, November 30, 2011 5:57 AM
  •  I am sure stummped on this.  By the way, below is my connection string.  Is this wrong as well?  If so, what should it be?  I have one database that I connect to for authentication (ASPNETDB) and one for the website (GolfScores)

     

    <add name="GolfScoresCN" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\GolfScores.mdf;User Instance=true" providerName="System.Data.SqlClient" />

     

    Thanks!

    Wednesday, November 30, 2011 6:15 AM
  • If you would have read the answers properly on the link I provided, you need to replace DEV1 with your machine name
    Life would have been much easier if I had the source-code !!
    Wednesday, November 30, 2011 5:28 PM
  • I apologize for my ignorance here Mohib and I sure appreciate your help.  I did replace the DEV1 with my server name, but still the same error.  If you have other thoughts for me, please let me know.  If you want to give up on me, I can certainly understand!  Again, thanks for your help here!
    Thursday, December 1, 2011 1:30 AM
  • I stummbled across a thread that explains how to run sql commands from the Command prompt.  So I have been trying that method.  The problem is, it never finds my database.

    I am using SQLCMD from a command prompt:

    If I type "select name from sys.databases"  it returns only master, tempdb, model, and msdb.  Why won't it show my user defined databases like ASPNETDB?

    Thanks!

    Thursday, December 1, 2011 3:06 AM
  • WOW, after all that messing around and it was as simple as adding this to the web.config:

    <identity impersonate="true" userName="ServerName\login" password="p455w0rd" />

    I did not have the username and password in my original Identity tag.  Hope this helps someone else!

    Thanks again Mohib for working with me!

    • Marked as answer by bcc_net Thursday, December 1, 2011 4:04 AM
    Thursday, December 1, 2011 4:04 AM
  • Great. It looks like an alternative to adding permissions to database for the server account so would come handy to anybody who is unable to do the same or doesnt want to make permissions changes in the database.
    Life would have been much easier if I had the source-code !!
    Thursday, December 1, 2011 5:30 AM