How to Rollback Asp.Net Membership Configuration(Tables&Procedures) - asp.net

I'm developing a project that works on remote server database tables. But there were no membership, only one admin panel with 1 admin user. So I tried to use Asp.Net membership for this, but when I did that according to tutorials(on C:\WINDOWS\Microsoft.NET\Framework\version\aspnet_regsql.exe"), I guess there was a conflict so my project didn't work. I found "Windows authentication" line in my web.config, commented out, fixed it.
Then I decided to use a master password inside the code, with text boxes. This is really simple application, no high-level security needed. So I did it so. But when I opened the database, I realized that Asp.Net created its own tables and stored procedures. Now I want to rollback my Asp.Net (Membership) configuration. I can manually delete the tables and procedures but I fear of doing something wrong. What should I do?
Thanks in advance.

Run aspnet_regsql from .NET command prompt and it will start a wizard. You can either configure or remove the tables.. The wizard gives you option for both.. Select the one you need and your tables etc will be deleted from the database...

If you're not using asp.net membership, then it will do no harm to manually delete them.

Related

Different user for migrations

I'm trying to run
dotnet ef database update
When I do so, I get an error about not being allowed to CREATE TABLE. Not entirely surprising as I don't want the user I have the website running under to be able to create tables. So, after a bit of searching I found a solution that basically created an inherited context, and with that context used a different set of credentials. So, I tried;
dotnet ef database update --context ScaffoldContext
And I got the same error. I checked my connection string, yes, it's a user I can use to create a table with. Confirmed through SQL CLI. So, I added CREATE TABLE privileges to my site user, and the error changed. Suggesting that the base connection string was the one that mattered and it's ignoring using my elevated user. I tried moving the configuration into the OnConfiguring override in my inherited scaffold context, instead of services.AddDbContext in my Startup.cs. However, looking this up it looks like the wrong way to go about that. When I added CREATE TABLE privilege to my site user, I got a different exception about not being allowed to touch dbo.
This is driving me nuts, I don't want to use my site user as my migration user and it seems every example I find is from older versions of EF or dotnet core. Does anybody have any solid guides on how to go about managing users correctly using migrations with 2.1?
Note: If I change my connection string to be my sa user, it works fine. So the migration will go through. I'm just not wanting to give either full privileges to my site user or swapping credentials around in connection strings every time I need to run a migration.

publish code only to Azure, without updating data

My Asp.net project uses an SQL db. I need to update the published version on Azure. It keeps failing on the db deploy. The thing is, all I need to update is the code. The current data are fine. Is there a way to tell it to go ahead and deploy the code and leave the data unchanged?
I figured it out. Under project settings, package/publish SQL, remove the database.

Creating a database project with Visual Studio - can't find database after running?

I am following this tutorial (http://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database) in order to create a database-first app with Entity Framework.
I hit "Run" and everything seems to be working, but in the next part of the tutorial (https://www.asp.net/mvc/overview/getting-started/database-first-development/creating-the-web-application), when I try to add a connection, it's not in the drop-down menu in the "Connection Properties" box under "Select or enter a database name".
Which server is the database on? I didn't specify anything about the server when I created the project for the first tutorial, and I figured that it would be on the default LocalDB that comes with Visual Studio (server name: (localdb)\MSSQLLocalDB), but the database isn't there. Any ideas where I should look or what to try?
Maybe use . (a dot) as Server Name?
Open your Web.config file and check your <connectionStrings> this is where the data source of the database will be. As shown:
However, which version of SQL Server do you have? As this can determine what the correct connection string will be.
Hit Windows+R. And run the following:
%LOCALAPPDATA%\Microsoft\Microsoft SQL Server Local DB\Instances
You may have multiple instances, it would be worth checking each one. So it would be:
(localdb)(name of instance)
This article may also be of use to you:
http://rajchel.pl/2015/10/solving-connection-issue-with-sql-server-2014-localdb/
What could be the case is that you have to run the application you created, and then do something to touch the database like creating / registering a user. After registration you can find the database on the specified location in your web.config settings. This was the solution in my case.

aspnet_regsql not generating all tables

For some weird reason, aspnet_regsql command only generates some and not all the tables in Membership database. For example, it doesn't generate dbo.Users, dbo.Roles, dbo.Profile etc. In fact it generates only 11 of the 17 tables. I have tried running it from the command prompt with different switches. Plus I have run it as admin too. No better. Does anyone know what am I missing here?
This is ASP.NET 4.0 + SQL Server 2008 R2 Express.
Right. Figured this out after a long day of effort. Here's the summary if anyone else needs it:
ASP.NET 4.0 includes a new set of providers that reside in a different namespace System.Web.Providers.DefaultXProvider, where X can be Membership, Role, Profile or SessionState. You should really use these in your web.config if you're targeting ASP.NET 4.0 or above. You can download these providers through NuGet by searching for Microsoft.AspNet.Providers.Core package.
The new providers do not use "aspnet_" prefix with the table names. So what used to be dbo.aspnet_Roles in previous versions is now dbo.Roles and so on. The new providers use only 6 tables. I had incorrectly created tables through both the old and the new providers on my development machine and that's why I thought it was missing some tables on the production server.
You do not need to explicitly run aspnet_regsql on your database. The first time you access your database through a Membership call, such as GetUser(), the provider will automatically generate the required tables for you if they do not already exist.
Hope this helps someone down the road.

Is there a way to rebuild/repair ASP.Net personalization tables without losing the data inside?

I inherited an Asp.Net app that uses ASP.Net membership services. I am trying to add web parts with personalization to the site, and am getting a lot of errors. It looks like the tables generated by Aspnet_regsql.exe have been changed - probably copied at some point in the past using "select into" causing them to lose all their indexes and primary keys.
How can I repair these tables without losing all the data inside?
Backup database (just in case!)
Rename existing database
Recreate aspnetdb
Bulk copy data from renamed DB into newly recreated DB. (probably with BCP)
I know BCP is an old tool... but it still works. Maybe there is an easier way to do it, but this is how I would do it.

Resources