I have recently discovered that ASP.NET MVC 4 uses SimpleMembership rather than the traditional ASP.NET Membership provider.
I am looking to use SimpleMembership but I also wish to use an Sql Server express database (I will be using a 'real' Sql Server db later on).
I am used to using aspnet_regsql to setup my sql server databases for application services and therefore inserting the necessary membership tables.
However, this application will not setup a DB to work with SimpleMembership.
Can anyone tell me how to do this?
You will need to comment out the WebSecurity.InitializeDatabaseConnection line of code (otherwise the first time you reach the login form the application will attempt to create the simple membership tables on the defined web.config connection string).
Then you will need to update your account controller code since its was written for simpleMembership use to reflect your chosen membership provider.
Recently I did this by creating an MVC3 project then upgrading it to MVC4 (read the how to upgrade mvc3 to mvc4 section). Not the cleanest but it did prevent me from having to update the account controllers code.
I would recommend to look into InitializeSimpleMembershipAttribute, which is in the folder "Filters"
There is a command to initialize the database. It checks itself, if the tables are already created.
WebSecurity.InitializeDatabaseConnection("connStringName", "UserProfile", "UserId", "UserName", autoCreateTables: true);
The tables are:
UserProfile => in my case, because of the initializer
webpages_OAuthMembership
webpages_Membership
webpages_OAuthToken
webpages_Roles
webpages_UsersInRoles
You can check out the source-code of the aspnetwebstack project
Related
I am working on a project which is in .net core and hosted on azure and being used as SAAS application by different clients all over the world having separate databases.
Now I got a requirement which says we should delete the databases of those clients which are no longer in master db and deleted by admin.
I am in doubt that should we really delete the database for the clients which would be getting deleted?
Also if yes is it feasible to delete the database through application or we should use some utility to do that?
Also I am afraid if server will allow application to delete the database?
Can any one please suggest me on this?
Following tech stack i am using:
.net core (backend) with EF core
MSSQL (database)
Theres a few different ways.. Essentially it works the same as any other database, so you can execute T-SQL to do it.. or use the Azure SDK.. Here is some examples of different approaches: https://learn.microsoft.com/en-us/sql/t-sql/statements/drop-database-transact-sql?view=sql-server-2017
You can execute raw SQL statements in EF like so:
using(var context = new SampleContext())
{
var commandText = "INSERT Categories (CategoryName) VALUES (#CategoryName)";
var name = new SqlParameter("#CategoryName", "Test");
context.Database.ExecuteSqlCommand(commandText, name);
}
So, using that format, you could add your DROP Database command in? Taken from: https://www.learnentityframeworkcore.com/raw-sql - under the Database.ExecuteCommand section
I'm new to microsoft Azure. I Had a Production Database .I am facing few issues
for Eg: XYZ Which will reference from 2 Other Databases.while Creating BACPAC file I'm Getting Error reference is not Allowed
How can I Overcome with The Issue.your Help will Appreciated.
SQLAZURE is database as a service,so you are actually working with only database and it is not connected to any other database,but all the databases are grouped under one logical server for administrative purpose
In your case, you will have to remove all the references from other servers or other databases..
Few more options..
1.You can use SQLSERVER in a VM
2.you can use elastic query
There is one more new service called SQLAZURE managed instance which will be in public preview during this years Microsoft Ignite.This service has all the capabilties of SQLAZURE(Like automatic backups,HA..) and also all the features of an OnPremise server like SQLAGENT,linked servers,clr...
To start with elastci query,below is one easy place to start
https://www.mssqltips.com/sqlservertip/4550/sql-azure-cross-database-querying/
According to Scaleout with SQL Server you can use SignalR.SqlServer to keep SignalR synced on a load balancing setup. I have an existing MVC 5 website with its own database created using Entity Code First. The article seems to use a dedicated database with service broker enabled and says not to modify the database.
So do I need to have a separate database for this? I know Entity can be picky if the database schema doesn't match and I worry that if I try to use the SignalR Sql Server package with the existing database that the tables it creates will cause a context changed error.
Also can someone provide me with more information about using the Microsoft.AspNet.SignalR.SqlServer package. The article I linked doesn't give a ton of detail and I don't know if I need to change anything in my hub and groups or if it is all handled automatically.
You should be able to, though you'd likely want to separate your entity framework definitions from signalR. You can either put SignalR in a separate database, or give the two a separate schema.
In terms of configuration, you'll need to make an addition to the Startup class of your web project:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var sqlConnectionString = "connection string here";
GlobalHost.DependencyResolver.UseSqlServer(sqlConnectionString);
this.ConfigureAuth(app);
app.MapSignalR();
}
}
I am using MVC4 with the default membership provider and using entity framework code first. The membership data is in a database stored in my app_data folder called aspnet-xxxxxx.mdf, and my application data is created in a separate database running on SQL Server express.
What do I have to do so that I have 1 database containing my membership tables and the application data? I do not mind losing the data in either of these databases as at the moment it is only test data.
Find your InitializeSimpleMembershipAttribute.cs and change in the line
WebSecurity.InitializeDatabaseConnection("[ConnectionString]", builder.Provider, "UserProfile", "UserId", "UserName", autoCreateTables: false);
[ConnectionString] to your connection string name you defined in Web.config. Or provide a complete connection string
We have a .NET3.5 Windows Forms application that calls an ASP.NET SOAP web service on the same server. This web service then saves the data into a SQL Server Express 2005 database, again on the same server.
The application has been deployed internally, as well as to a number of our customers and has worked as expected for over 18 months. However this week, at our main customer's site, the application has started generating an error message on four out of the 10 servers it is deployed on. All of the web service methods use the same connection string, but only one web method is affected.
The connection string has this format:
Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=MyDatabase;
Persist Security Info=True;User ID=MyUser;Password=MyPassword
When the application calls one particular web service method, it is producing an error:
Cannot find the user 'MyDatabase', because it does not exist or you
do not have permission.
There have been no changes to the application to cause this, however the customers' IT people may have made changes to these servers. MyUser has been granted permissions on the stored procedures and is able to connect to all of the other web service interfaces.
The main thing that is confusing me is that the error messages says that the user that does not exist is MyDatabase which is the Initial Catalog name in the connection string.
I have been onsite with the customer and verified that the application is still set up correctly and that all of the other web service interfaces are correctly connecting to the database.
Any suggestions of either possible causes or other things I can check would be gratefully received.
I would strongly advise against removing the dbo. That is the schema name. Simply removing it will imply to the DB to use the default schema, which is probably dbo anyways. So it would accomplish nothing. But by not using the schema name when calling the procedure you can run into naming conflicts. For example, if you have a procedure with the same name in two different schemas in the DB, and you try to call it without a schema name, the DB will not know which one to call, resulting in an exception.