Run Migrations command if not have visual studio - asp.net-mvc

I'm publishing a website ASP.NET MVC and get this error:
“Migrations is enabled for context ‘Context’ but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the ‘Update-Database’ command from the Package Manager Console.”
I can't install visual studio on server so i can't run ‘Update-Database’ command.
How to solve this problem ?

Find migrate.exe (YourApp\packages\EntityFramework.6.1.3\tools) and paste it in bin folder on the server.
Open Command Prompt on the server.
Run below commands
cd "C:\Websites\YourApp\bin" migrate.exe YourAppName.Api.dll /startupconfigurationfile:..\Web.config /verbose
Please Note that YourAppName.Api.dll should be the DLL having Enabled Migration.

you do not need to install visual studio on the server.
if you have your database connection string setup in web.config you should be able to run update-database in the package manager console and it will update your database on your web host.

Related

Database migration for .Netcore MVC project in Mac

I am just into dotnet and I am finding it difficult as most of the resource is available only for windows.
I have the docker running. When I try to update the database (dotnet ef database update) in the command terminal, it builds and shows an error saying "Connection string keyword 'server' is not supported."
The project is empty and its the default one after creating a new project with MVC
For incorporating Server in the visual studio I made few changes in the app settings.json
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=leavemanagementnet6;User=SA;Password=MyPassword123#;"
},
By default, it uses SQL Lite. Under program.cs, it should be changed to UseSqlServer(connectionString).
Also, the default migration has to be removed and created again. If its not done, we will be facing error while updating.
dotnet ef migrations remove
dotnet ef migrations add CreateIdentity -o Data/Migrations

Entity Framework add-migration when using Vagrant

I'm using vagrant to host my DB and website, but I make changes to my project locally and push changes to the vagrant site. I can run migrate.exe to update the DB but I can't figure out how to run add-migration? If I run it locally, it says I have pending changes because I have no DB locally? Can anyone point me in the right direction?
One option to update database without use dotnet ef database update is execute the command bellow in some default action or startup routine
_dbContext.Database.Migrate();

Entity Framework migrate.exe not working after updating to AspNet.Identity

Since updating my solution to use ASPNET Identity instead of the old membership, the migrate.exe commando to update database schema stopped working. The only major change is that my Context now inherits from a IdentityDbContext, when before it inherited from a DbContext.
Everything works fine running update-database on package manager console, but using migrate.exe on the command line doesn't work anymore. I get the error:
System.Data.Entity.Migrations.Infrastructure.MigrationsException: No migrations configuration type was found in the assembly 'SampleProject.Repository.EF'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
I have a Configuration.cs file for the migrations, as always had and when running the "enable-migrations" suggested I get a message saying that migration are already enabled for the project.
Does anyone knows what the problem might be?
Thanks
Just a quick update on the solution.
It was DLL version conflict when running migrate.exe.
I was using the output from my web project (which also contained DLL for the EF project).
I updated it in order to use the bin content of my EF project and it worked just fine.

.mdf file not able to attach at runtime MVC4

ERROR:
Cannot attach the file 'C:\Users\dboyle\Desktop\New folder
(2)\OilNGasWeb\OilNGasWeb\App_Data\aspnet-MvcApplication4-20130726115749.mdf' as database 'aspnet-MvcApplication4-20130726115749'.
*This error occured after deleting my Web.config file *( replacing it with a new one from a new project and replacing the default conection string with what i needed)
EDIT:
Sofar I have tried deleting the .mdf physical file and from VS, also from SQL. Then re-running the update from the package manager within VS. The database gets made, yet same error persists.
I have found
<ObjectGroup Name="DefaultConnection" Order="1" Enabled="False">
<Destination Path="Data Source=ANE-SQL\ANESQLSERVER;Initial Catalog=OilGas;User ID=software;Password=GLvp$102" />
<Object Type="DbCodeFirst">
<Source Path="DBMigration" DbContext="OilNGasWeb.Models.OilNGasDB, OilNGasWeb" MigrationConfiguration="OilNGasWeb.Migrations.Configuration, OilNGasWeb" Origin="Configuration" />
</Object>
</ObjectGroup>
in my website.pubxml file ( it still shows my old database name ) will this interfier?
While doing database update using code-first migrations in ASP.Net MVC, came across the strange exception and details are as follows,
Issue back ground details,
Manually deleted auto created ".mdf" file from App_Data folder using Visual Studio.
Executed update-database in package manager console. Then got the below exception,
System.Data.SqlClient.SqlException (0x80131904): Cannot attach the file 'E:\Backup\Practice\MVC4\DotNetExamples\DotNetExamples\App_Data\DotnetExamples.mdf' as database 'DotnetExamples'.
Solution:
If you delete the DB file, it still stays registered with SqlLocalDB. Sometimes it fixes it by deleting DB. We can do this from the command line.
Open the "Developer Command Propmpt for VisualStudio" under your "Start/Programs menu->All Programs->Visual Studio 2012->Visual Studio Tools"
Run the following commands:
sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
Please have the .mdf file and SSMS instance of the Database Deleted.
Now execute "update-database" command from package manager console and it will create database for you without any obstacles.
You probably have an attached db with the same name in your SQL Server, just open up SQL remove it and run your MVC4 again.
I had the same problem.
I used Visual Studio 2015 and SQL Server LocalDB v12 so the answer from the accepted answer didn't work for me. I used these commands instead (without version) and it worked:
sqllocaldb.exe stop
sqllocaldb.exe delete

Upgrading TFS 2005 to TFS 2010 - Migrating Sharepoint site

I recently did a migration upgrade from TFS2005 to TFS2010. Everything works, but the Sharepoint site wasn't migrated.
I attempted running the command below:
stsadm.exe -o addcontentdb -url http://NEWSERVER/sites -databasename STS_Content_TFS -databaseserver NEWDB
but I got the following error:
The pre-upgrade scan tool has not yet been run on this database SPContentDatabas
e Name=sts_content_tfs Parent=SPDatabaseServiceInstance. You must run the pre-up
grade scan tool before you can continue with the upgrade process. Run the tool f
rom the following path: C:\Program Files\Common Files\Microsoft Shared\Web Serve
r Extensions\12\bin\prescan.exe.
Unfortunately I have upgraded WSS from WSS2 to WSS3 on my source server, so I am unable to use prescan.exe.
Any other way to migrate the Sharepoint site from the old server to the new server?
Thanks
SQL Server: Connect to STS_Content_TFS
update Sites SET BitFlags = 262144
then follow steps here: http://msdn.microsoft.com/en-us/library/cc668750.aspx

Resources