ProfileManager.DeleteProfile and/or Membership.DeleteUser error

Posted on 2010-01-07
Last Modified: 2012-05-08

The ProfileManager.DeleteProfile and  Membership.DeleteUser methods work fine when I run my web application through the VS2008 debugger. But, not on the webserver (using IIS). The error indicates that it can't find the SQL server, but every thing else using the SQL server database works fine (so it's not a connection string issue).

For example this works fine on the webserver too:
allUsers = Membership.GetAllUsers();
                gvwUsers.DataSource = allUsers;

It's just the ProfileManager.DeleteProfile and  Membership.DeleteUser methods that don't work on the webserver (but they do work locally running in the VS2008 debugger). Code is attached.

Thanks very much,

This is the stack trace:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4845255
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4858557
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +376
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4859683
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4862012
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +82

[HttpException (0x80004005): Unable to connect to SQL Server database.]
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +137
   System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +94
   System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +25
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +395
protected void gvwUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)


            string userName = gvwUsers.DataKeys[e.RowIndex].Value.ToString();




            lblTotUsers.Text = allUsers.Count.ToString();


Open in new window

Question by:Bill732
    LVL 41

    Expert Comment

    my guess....
    make sure your Profile provider is set correctly pointing right database in the web.config.

    Author Comment

    Thanks for responding  so quickly. Yes, does point to the correct database.

    Since the method to select all users worked, but the method to delete a user didn't work, I thought maybe it would have to do with permissions. But, that's not what the error message was.

    Also, why does work without error when running through the VS debugger but not on the web server?

    Accepted Solution

    OK, I found the problem.

    I should not have ProfileManager.DeleteProfile(userName); in my code because I'm not using profiles!!!!!

    Since I don't have  a profile provider section in my web.config, ProfileManager.DeleteProfile tried to use the default profile provider from the machine.config - which is AspNetSqlProfileProvider and the LocalSQLServer.

    When ProfileManager.DeleteProfile fires and it doesn't find the default provider database (LocalSQLServer) it will try to create one!! I noticed that after I ran through my local VS2008 debugger, it created a new aspnet database to the App_Data folder!! I didn't expect that!

    Running on the webserver caused and error instead since the webserver won't allow the web app to create a new database. It eventually errored out and said that it couldn't connect to the database.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now