Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ProfileManager.DeleteProfile and/or Membership.DeleteUser error

Posted on 2010-01-07
3
Medium Priority
?
971 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:Bill732
  • 2
3 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 26206189
my guess....
make sure your Profile provider is set correctly pointing right database in the web.config.
0
 

Author Comment

by:Bill732
ID: 26209645
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
 

Accepted Solution

by:
Bill732 earned 0 total points
ID: 26210485
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

578 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