开发者

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

开发者 https://www.devze.com 2023-01-19 04:59 出处:网络
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:

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

精彩评论

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