I set connection string in my Startup.cs (Startup class and ConfigureServices method). Sample code below:
if (_currentEnvironment.IsProduction())
{
connectionString = "ProdConnection string here ..";
}
else
{
connectionString = "Devl connection string here ...";
}
In the Package Manager Consoler of my Visual Studio 2017, when I do an Update-Database -Migration someMigration it always applies it to Devl database even when the environment is set to production.
How can I force it to connect to production?
The hosting environment uses environment variables to determine the current environment. In the package management console, be sure to set this environment variable before running the EF Core commands:
$env:ASPNETCORE_ENVIRONMENT="Production"
Related
I can deploy a dotnetcore3.1 runtime using this input in my terraform (executed from GitLab CI pipeline):
variable "runtime" {
type = string
default = "dotnetcore3.1"
}
After it deploys, I can manually change the runtime from .NET Core 3.1 to .NET 6:
But how do I specify .NET 6 in the terraform to begin with?
I have tried:
variable "runtime" {
type = string
default = "dotnet6"
}
But I get the following error in my pipeline:
Error: expected runtime to be one of [nodejs nodejs4.3 nodejs6.10 nodejs8.10 nodejs10.x nodejs12.x nodejs14.x java8 java8.al2 java11 python2.7 python3.6 python3.7 python3.8 dotnetcore1.0 dotnetcore2.0 dotnetcore2.1 dotnetcore3.1 nodejs4.3-edge go1.x ruby2.5 ruby2.7 provided provided.al2], got dotnet6
How does one select the .NET 6 runtime in TF?
It would seem that .NET 6 isn't supported via Terraform.
This is not entirely true, the AWS provider supports dotnet6 runtime, you just have to have a version of the provider has support for it.
Currently the latest version of the AWS provider is 4.27.0. The support for dotnet6 was introduced around version 4.4.0. Adjusting the provider to have a version greater than 4.4.0 should be enough to have dotnet6 support.
So you would want to modify your required_providers block to something like this:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">=4.4.0"
}
}
}
dotnet6 works just fine.
I suspect your TF version and/or AWS provider are out of date. I'm using dotnet6 for a lmabda just fine with the following..
"terraformVersions": {
"terraformMajorVersion": "1",
"providerVersions": {
"aws": "4.14.0",
}
I am using an M1 Max MacBook and am using docker to run Azure SQL Edge. I have a database created in Azure Data Studio with the location "localhost" and name "localhost".
I am following along a ASP.NET Core tutorial and am trying to figure out how to rewrite the AppSettings.json file to access the database I created. Right now I can't figure out how to connect the database I have to my project in Visual Studio for Mac. My end goal is to run to able to run 'dotnet ef database update' in my project to update that said database. Sorry if this is hard to follow, I am a really big noob. But this is what I have right now in the AppSettings.json file:
{"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Error"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"CodeCamp": "Data Source=localhost;User Id=sa;Password=MyPass#word; Initial Catalog=PSCodeCamp;Integrated Security=True;Connect Timeout=30;"
}
}
As of now you have already added your Database Connection string in appsettings.json. looks like below
{
"ConnectionStrings": {
"TestDatabase": "Server=(localdb)\\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;"
},
}
Once you added your connection string in a appsettings.json. check the Startup.cs file, and find a method called 'ConfigureServices' add the dependency injection there.
To configured in Startup.cs with the connection string being read from configuration. Note the GetConnectionString() method looks for a configuration value whose key is ConnectionStrings:<connection string name>. You need to import the Microsoft.Extensions.Configuration namespace to use this extension method.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<TestContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("TestDatabase")));
}
Refer here Link 1 & Link 2
We are trying to update the schema of an Sqlite database during continuous integration. Here is a simplified version of our scenario.
The deployment script publishes the project.
cd App
App> dotnet publish <args>
That creates the following directory structure.
artifacts/
App.dll
Database.sqlite
The-rest-of-the-publish-output
web.config
App/
Migrations/
Program.cs
project.json
Startup.cs
The deployment script then runts the migrations.
App> dotnet ef
--assembly ..\artifacts\App.dll
--startup-assembly ..\artifacts\App.dll
database update
The issue is that we receive the following message:
Unexpected value '..\artifacts\App.dll' for option 'assembly'
We have also tried other ways to run dotnet ef database update on the compiled project but have not been able to determine how to update the database in the artifacts directory.
In our current scenario, we do it like this on Startup.cs:
if (migrateDb)
{
try
{
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
}
}
catch { }
}
while on development migrateDb resolves to false so we can add/remove and apply migrations as desired. On production that will resolve to true for convenience.
There may be well more valid/appropiate options, usually depends on the context and/or project needs. This is just one way of many.
As a test I tried connecting to a DB2 server using the QODBC driver. I did this by creating a DSN and then providing the needed data such as hostname and the rest.
But what if I want to run my app in another computer. Is there another way to connect to a DB2 database, because as I see it this would also limit me if I tried to compile and run my program in iOS.
You can use QSqlDatabase class like this:
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QDB2");
db.setHostName("mozart.konkordia.edu");
db.setDatabaseName("musicdb");
db.setUserName("gbatstone");
db.setPassword("T17aV44");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
[EDITED]
How to Build the QDB2 Plugin on Windows
The DB2 header and include files should already be installed in the right directories. You just have to build the plugin as follows:
cd %QTDIR%\src\plugins\sqldrivers\db2
qmake "INCLUDEPATH+=<DB2 home>/sqllib/include" "LIBS+=<DB2 home>/sqllib/lib/db2cli.lib"
nmake
If you run IIS Express from the command line, anything you write Console.Out in your web app is displayed in the command line output. This is very handy for trouble shooting LINQ to SQL translation issues if you set DataContext.Log = Console.Out. However, if you check "Use IIS Express" in the web project properties in VS 2010 SP1 you never see the command line.
Can you redirect IIS Express Console.Out to a log file or something?
I found a way to write directly to the Debug Console window via damieng's blog:
class DebugTextWriter : System.IO.TextWriter {
public override void Write(char[] buffer, int index, int count) {
System.Diagnostics.Debug.Write(new String(buffer, index, count));
}
public override void Write(string value) {
System.Diagnostics.Debug.Write(value);
}
public override Encoding Encoding {
get { return System.Text.Encoding.Default; }
}
}
You can attach it to a DataContext like you would with Console.Out:
#if DEBUG
db.Log = new DebugTextWriter();
#endif
http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers
You can see console output, if you setup 'image file execution option' for iisexpress.exe. Only issue is, you will see a popup console window when a new iisexpress.exe is started. You can setup this only when you want to see console traces.
Do following to setup image file execution option:
install windbg from http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx
Setup following registry key (This link may help you http://msdn.microsoft.com/en-us/library/a329t4ed(VS.71).aspx)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\iisexpress.exe]
"Debugger"="c:\\windbg -g -G"
You can disable image file execution option by renaming or deleting above registry key.