How to specify the folder to create SQL database using dotnet ef - entity-framework

I am using Dotnet EF Core, and have created migrations. When I run
dotnet ef database update
the database is created in my windows user folder.
My connection string is
"ConnectionStrings": {
"ContextConnection": "Server=(localdb)\\MSSQLLocalDb;Database=MyDb;Trusted_Connection=true;MultipleActiveResultSets=true;"
}
How do I get the database created in the project directory? (without having to have the full project pathname in the connection string) Using VS2015 I was able to include |DataDirectory| in the connection string.

These CLI commands can be run from the command line by navigating to the project directory
I think you are trying to run CLI commands directly from user profile hence database is created in your windows user folder.
First, navigate to your project directory by using simple dos commands (e.g. CD)
And then run these CLI commands-
dotnet ef [options] [command]
One of the option-
-p|--project <PROJECT> The project to target (defaults to the project in the current directory). Can be a path to a project.json or a project directory.
For more information refer this link-
https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html#dotnet-ef
See if this helps.

Related

.NET Core - how does the 'dotnet publish' command work?

I have a solution with some projects targeting .NET Standard 2.0 and a console application project targeting .NET Core 2.1.
I set "myFolder" as the output folder.
Building from VisualĀ Studio, I get all DLL files in:
"myFolder\netstandard2.0"
"myFolder\netcoreapp2.1"
I get the same using the "dotnet build" command.
Now I need my console application's EXE file.
So I use the "dotnet publish -c Release -r win-x64 MySolution.sln" command.
Now I get this new directory, "myFolder\netcoreapp2.1\win-x64", where I find all DLL files and the console application's EXE file.
Not enough!
I find one directory more, "myFolder\netcoreapp2.1\win-x64\publish", where I find again all DLL files and the console application's EXE file.
Which meaning do they have? I read the command documentation, but I didn't find my answer.
Per the documentation
-o|--output <OUTPUT_DIRECTORY>
Specifies the path for the output directory. If not specified, it defaults to ./bin/[configuration]/[framework]/publish/ for a framework-dependent deployment or ./bin/[configuration]/[framework]/[runtime]/publish/ for a self-contained deployment.
dotnet publish -c Release -r win-x64 --output ./MyTargetFolder MySolution.sln
All you really need to understand to be able to successfully publish and deploy is that you need to dotnet publish and ensure that you have a Release configuration -c Release, as well as any other required options on the command line.
All of your files will be in the 'publish' subfolder, e.g. ./bin/Release/[framework that your solution is targeting]/publish. The files contained here are everything that is needed for a running instance of your application/service. The MySolution.dll is the entry point for your app/service, and will automatically link to all of the other dependencies and configuration stored in the publish folder.
To configure and deploy a running instance, you need to work out how to deploy all of those files to a server, and somehow configure something (e.g. a web server, runtime, service host ...) to call your MySolution.dll.
Note that in your dotnet publish you're specifying -r, which means that your application is targetted to run under 64 bit Windows, as opposed to a Linux distribution or OSĀ X (which makes it less portable, but it has the advantage of isolating your application from changes to an installed runtime on a server that you deploy it to.). That's why you're seeing an extra folder win-x64.
Also you're explicitly building from the solution configuration specified by your solution file MySolution.sln, which is probably the most reliable thing to do as this will ensure that any projects used as dependencies by your solution (which is a typical good practice) will be included in the build/publish.

How to deploy ABP to IIS

I have a ABP template. It is a merged solution for Angular in Full .Net framework. I have already created a published package by right clicking on the Web.Host project and then Publish.
Here is a screenshot of my published folder:
I have also added a website in my local IIS and have pointed it to the wwwroot folder of my published folder as localhost:8081
I have modified the appconfig.json in the wwwroot/assets folder as:
{
"remoteServiceBaseUrl": "http://localhost:8081",
"appBaseUrl": "http://localhost:8081"
}
and have also changed appsettings.json to
"App": {
"ServerRootAddress": "http://localhost:8081/",
"ClientRootAddress": "http://localhost:8081/",
"CorsOrigins": "http://localhost:8081,http://localhost:8081"
},
Do I need to add another Website in IIS for host? If Yes, where should I point it to? Again wwwroot? All the DLLs and appsettings.json are above the wwwroot. Should I bring them all inside the wwwroot?
When I navigate to the localhost:8081 I get "Resource not found" prompt
I noticed that there is a Web.Host.exe file in the Published folder. When change all above settings to localhost:5000 and execute it, it runs the host on localhost:5000 and works fine for both localhost:5000/swagger and localhost:5000/app/
Do I need a website under IIS to execute the Web.Host.exe? If yes, how would I add such website? Where that port 5000 has been set for the .exe file?
If I change the website physical folder to the published folder (which holds the wwwroot folder) I get the following error (seems something is wrong with the web.config file):
You need the .NET Core Hosting Bundle.
Install the .NET Core Hosting Bundle on the hosting system. ...
a. Navigate to the .NET All Downloads page.
b. Select the latest non-preview .NET Core runtime from the list (.NET Core > Runtime > .NET Core Runtime x.y.z). ...
c. On the .NET Core runtime download page under Windows, select the Hosting Bundle Installer link to download the .NET Core Hosting Bundle.
...
Restart the system or execute net stop was /y followed by net start w3svc from a command prompt. Restarting IIS picks up a change to the system PATH made by the installer.
Reference: https://learn.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x

Updating database to Migration Configuration

I have pulled down a Visual Studio 2015 project created my another developer. Within the Migrations folder are several Migration Configuration files ...
201601081315335_AddedPersonEntities.cs
201601091532275_AddedDepartmentEntities.cs
201601101145137_AddedPayrollEntities.cs
I would like to update my database to the point of one of these Migration Configurations. However when I try this command ...
Update-Database -Verbose -StartupProjectName MyApp.Api -ProjectName MyApp.Data -ConfigurationTypeName 201601091532275_AddedDepartmentEntities.cs
I get the following error ...
The migrations configuration type '201601091532275_AddedDepartmentEntities' was not be found in the assembly 'MyApp.Data'.
I was expecting it would bring my database up to the same schema at the point that 201601091532275_AddedDepartmentEntities was created. Am I missing something?
Go to visual studio, select your MyApp.Data and check the "Show All Files".
Inside the migrations folder, see if there aren't migrations "outside" the project. If there is, then add them to the project with Right-Click > Include in project.
Do you use TFS?
It happens when you add something (File/Folder) inside a project in your solution and check-in your solution, and your colleague doesn't do correctly the merge on the .csproj file (Which contains all the information about the files and folders inside the project).
WAIT
Ok i think this isn't the problem.
You are specifying -ConfigurationTypeName: don't you want -target: instead?
-ConfigurationTypeName Is used to define the configuration class (Normally contains the seed method).
-target Specifies to where you want to update your database (From the current migration to that specific one, forward or backwards it works anyway).
And, do you insert the models inside MyApp.Data or MyApp.Models?

Pack a Zend Framework app and deploy it on Zend Server

I created a small Zend Framework application from command prompt using Zend_Tool.
I deployed it in apache server htdocs folder and it is running fine.
Now I need to deploy it to Zend Server. For that i used a command zdpack pack appname.
While trying that i am getting lot of errors like
deployment.xml is missing
I created it in the app root folder.
Then i got
appnaama/data folder is missing error
I created a data folder.
Then
zend-scripts missing
error....
Please help me in deploying an applicaiton created from zf create project projname in Zend server and run it in the browser.
You need to come out of the directory when calling zdpack pack command. If you pack the file inside the project directory you get the "deployment.xml is missing" error.
Pass the following commands at the location where you are creating the
zpk file. For illustration, I will be doing it in the myapp folder of my desktop.
C:\Users\lura\Desktop\myapp> zdpack.exe create demoapp
Move into the directory using cd demoapp and list the directory. Copy your php codes into the data folder. The scripts folder and deployment.xml file can be left as it is. Next run the validate command when inside the directory.
C:\Users\lura\Desktop\myapp\demoapp> zdpack.exe validate --schema="C:\Program Files (x86)\Zend\ZendServer\share\deployment.xsd" deployment.xml
now you can move a folder back with the command cd .. and execute the following.
C:\Users\lura\Desktop\myapp>zdpack pack demoapp
That's it! The zpk file is created! A screenshot of my cmd.
This YouTube tutorial will help, if your still confused. To execute on Linux and for more info read this documentation from zend.
You are using zdpack command wrong!
Step 1: Open shell and ls or cd into the zend workspace.
Step 2: use "zdpack create <ProjectName>" command. It will create deployment.xml, data and script directories. Refresh project explorer you will see changes.
Step 3: Configure deployment.xml if needed.
Step 4: Use "zdpack pack <ProjectName>" command to create zpk file.
That's all.
I think you just pass incorrect path to the app.
Try following this scheme:
zdpack pack <path>/ProjectName
to generate required files.
Step 1: Create skeleton from the zend server zdpack command
#/usr/local/zend/bin/zdpack create <project-name>
It will create project skeleton.
Step 2: Configure deployment.xml if needed.After that check your Deployment.xml is valid.
# /usr/local/zend/bin/zdpack validate --schema="/usr/local/zend/share/deployment.xsd" deployment.xml
Step 3: Now create the zpk file for the aplication
# /usr/local/zend/bin/zdpack pack <project-name>

EF 4.3 migrations throwing "Unable to open configSource file"

I'm trying to use EF 4.3 migrations feature. My ASP.NET MVC project stores connection strings in external file:
<connectionStrings configSource="bin\connections.config" />
All runtime procedures (including automatic migrations) work fine. However, no powershell commandlet, connecting to the database, is able to find external file. It throws "Unable to open configSource file" exception. I was trying to place .config file in different places as well as changing configured external file location to no avail. Is there any workaround available?
Update: I've found that EF creates a temporary AppDomain with configuration file located in temp directory. So the only workaround at the moment, it seems, is to place external configuration in the same temp directory. Any other suggestions?
Using EF 6.1 here.
If like me you were linking to a connectionStrings.config file located in another project than your Entity Framework migrations project (using Add as link), you'll probably need to move the file back to this EF project and link to the moved file from the other projects instead...
There are unfortunately no easy way to handle external configSource files with the powershell cmd-lets in EF migrations. I've given up on it and moved the connection strings into the config file for the class library that contains the db code. The alternative is, as you've found out yourself to manually copy the file. Unfortunately the copy process doesn't honor the build settings of the project, so setting the external config file to be copied at build doesn't help.
EF 4.3.1 supports configSource.