I create a new MVC project with user authentication by the following commands.
dotnet new mvc -o ProjectName --auth Individual
However, it's using sqlite database by default. I know that adding -uld will use localDB instead.
I would like to ask if there is any way to use SQL Server directly.
I tried to migrate the sqlite database to SQL server database but there are some error messages during the migration.... Thus, I would like to ask if there is any better way to do it.
Thank you.
Related
On SQL Server 2008R2, we have a SQL login tagged with the sysadmin server role. Anytime a db is created, this login is automatically added as a user to the db. Is there a switch that will prevent this from happening?
EDIT:
Based on the answer below, I am adding more background info to explain why we want to do this.
When we publish to a new database from a Visual Studio SQL project, the publishing engine wants to add a user to the database. The username already exists as a login to the database (in the sysadmin server role -- and not much we can do about that), so the publish fails as the user gets auto-added by SQL server after the 'create database' statement. I was hoping for a switch that would tell SQL Server to not add the user automatically. So it seems we will have to find another solution on the VS side that tells the publishing engine to ignore the SQL DB user.
Assuming you're talking about the sql-server role, I don't think so. TBH if you're contemplating keeping a sys-admin out of a db, then you've got a different problem than the one you think you have...
I have a resolution to this. Download the latest SSDT package from MS and now there are new options under the Publishing Wizard Advanced... button to exclude the publishing of logins, roles, etc. The SSDT package I downloaded I found here...
https://msdn.microsoft.com/en-US/dn864412
This came up once before: Use DataContext.CreateDatabase in SQL Azure
The answer accepted was "maybe it's not possible". Didn't seem like a full answer.
I have a set of classes fully defined and I am wanting to create a database on Azure for this. It's not working because the USE statement does not work: http://msdn.microsoft.com/en-us/library/azure/ee336288.aspx
So, the database gets created as blank, and internally Linq generates a USE statement to move to that database and start adding tables. This fails and it throws an exception.
So how can I create my database? Can I use Linq to add tables to an existing database? Can I enable USE on Azure somehow? Seems ridiculous this does not work.
After messing around for a while on this, I ended up creating the database against a local SQL Server instance. Then used SQL Server Management Studio -> Tasks -> Script Database, and turned on the export type to be Microsoft Azure. Then I had the script file needed to run on the Azure server. I'll leave the question open for a day or two because I am curious if this can work with Azure directly somehow. If I don't hear anything, I will close it.
The USE statement does not switch between databases in Azure SQL Database. You will have to connect to the database to create a table on that database.
Regards
Dhruv
I'm working through this tutorial:
Deploying an ASP.NET Web Application to a Windows Azure Web Site and SQL Database
In the second part "Enable Migrations and create the database" I need to use the NuGet Package Manager console to enter a series of commends:
enable-migrations -ContextTypeName ToDoListApp.Models.ToDoDb
add-migration-initial
update-database
Why do I need to do this explicitly? Shouldn't this be wrapped up in the publish process?
Thanks
Dave
The migrations process is separate from Azure. You can have an MVC 4 project that uses database migrations but the database is not hosted on Azure. The commands you are referencing simply enable the migrations in any MVC 4 project.
I find updating the database dangerous, so I actually prefer it to be separated from the publishing process because this way someone on your team is able to update the logic of the website without pushing updates to the database.
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First database. Now I would like to create a comprehensive zip file containing the database, the application package generated by Visual Studio 2010 and a script to deploy everything to a Windows 2008 server with IIS7 and SQL Server 2008 with a prepared (but empty) database.
I don't foresee any problems with the deployment of the application package, but I'm unsure of what approach to use in deploying the database. The target environment already has an empty database that's been assigned to me, but I've been told that dropping and creating the database is fine.
From what I've read, I can do a straightforward copy of the .mdf and .ldf files to the server and then setup my connection string to point to that specific file but this approach sort of ignores the database that has already been created (or at least named) for me. The other approach would be to use the the existing .mdf to create the database on the server with a script. My only issue here is that I would like to keep the database name assigned to me.
I usually connect to my development database locally using SQL Management Studio and right-click the database, choose Tasks -> Generate Scripts. Then I select the entire database or just the tables I'd like to keep, click next, then click the Advanced button and make sure that I am scripting out "Schema and Data", and then generate a sql script that I can run on the production database, therefore keeping the table structure and the data that was in the dev database. Obviously, if you don't want to keep the data then just script out the Schema only. Then, point your application's connection string to the new production environment database and you're good to go.
I would like to install membership and roles to a specific database. It seems to create a new database : aspnetdb. I tried using the GUI (Wizard) but that installed personalization. I tried adding "...Localhost/DatabaseName" but that didn't work.
See the command-line options at ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)
Specifically, -d <database>:
Specifies the name of the database to
create or modify for use with
application services. If the database
is not specified, the default database
name of "aspnetdb" is used.