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.
Related
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.
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.
Does anyone have any best practices around deploying database changes in an EF 4.1 code-first solution? I know MS does not currently support database migrations for EF 4.1, but obviously people are going to need to do this from time to time.
Thanks
Once you deployed database to production you must do incremental changes. It means that before you deploy next version you must prepare two databases in your dev box:
Database with DB schema currently deployed in production - you should be able to get this from source control so always correctly label / tag your production releases
Database with new DB schema
Once you have two databases you can use some tool to make difference SQL script for you. I have experience with both:
Visual Studio 2010 Premium / Ultimate Database tools
Red Gate SQL Compare
These tools are for SQL server.
Once you have difference script you can test it on your dev box. Be aware that some more complicated changes cannot be created by difference script and require you to create custom migration script for example with storing data existing data in temporary tables while refactoring real table. Also if you use some new seed data in your new version you must add them manually into script or use Data Compare tools (also offered by both products).
After that you can plan outage of your production application, database backup and running upgrade script.
I have a number of manually written scripts (.sql) for tables, views and stored procedures that are used from an ASP.NET application. These scripts drop the object and recreates them. I need a way to update the database when the scripts change without deleting the object. For example, when a column is added to an existing table that has rows in it, I would need to update this table with this extra column without losing the rows.
I need a way to "update" the database on a single click (I can hook up the changes using a batch file). Does Visual Studio support this kind of functionality?
If you get Visual Studio Team System - Database Edition 2008 - which is now bundled with "Developer Edition" for free - it handles that. Visual Studio database projects without that edition really just store the static SQL that you want to track. The Database Edition is capable of determining the 'deltas' between your SQL and what's in a target database, generating that script, and executing against your database. You do get the option of reviewing that generated SQL, but by default it is very safe [it won't run if it thinks that there will be any data lost].
Yes - it's called Database Projects.
You can define a Visual Studio Database Projects, have create and change SQL scripts inside it, and then execute those against a database connection of your choice when you need to.
See this blog post here for a great explanation, or read the whole series that the 4 guys from Rolla wrote.
I am having an application in both windows and web domains.The web part of it have only limited features compared to it's windows counterpart.But for my case (an appointment fixing module which is done using both domains),I want both databases to update with the other database.Can anyone help me please.
1.You can create some trigger logic to do updations.
2.You could create a seperate exe or service that polled both databases
based on some key like lastupdated
and synchroized data.
All this is based on your data/table structure and how it is entered and structure.