ProfileManager.DeleteProfile and/or Membership.DeleteUser error

Hello,

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;
                gvwUsers.DataBind();

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,
-Bill

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();
            ProfileManager.DeleteProfile(userName);
            Membership.DeleteUser(userName);
            BindUsers(true);
            lblTotUsers.Text = allUsers.Count.ToString();
        }

Open in new window

Bill732Asked:
Who is Participating?
 
Bill732Author Commented:
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.
0
 
guru_samiCommented:
my guess....
make sure your Profile provider is set correctly pointing right database in the web.config.
0
 
Bill732Author Commented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.