开发者

How to force Sqlservices.Uninstall to delete old data too?

Does I use SqlServices.Uninstall() to uninstall ASP.NET Membership tables and other stuff programmatically from database. But when tables hold old data, it does not work with following error message:

Cannot uninstall the specified feature(s) because the SQL table 'aspnet_Membership' in the database '[DBNAME]' is not empty. You must first remove all rows from the table.

Is there a way to tell SqlServices or any other class in .NET to erase those old data too?开发者_C百科


You can use the following that deletes every user from your database.

foreach (MembershipUser user in Membership.GetAllUsers())
            Membership.DeleteUser(user.UserName, true);            
        SqlServices.Uninstall()

Be careful:

The code above executes 1 + N (DELETE Statements) + SQL Statements from the Uninstall method, where N == Number of Users in the database. So it's not very efficient.

If you want something more efficient you have to write your own Stored Procedure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜