Different appsettings.json configuration for the same dotnet core program on the same server - json

I have dotnet core program that I would like to install 2 different configurations(development and test) of on the same server but using different appsettings.json files.
One needs to use appsettings.Development.json
The other must use appsettings.Test.json
Normally, appsettings.json are selected by looking up the value of the System variable called, DOTNET_ENVIRONMENT on the server.
Is there anyone who knows a method to deploy the same piece of software on the same server and there use different appsettings.json files?

There is else way to define the ASPNETCORE_ENVIRONMENT, in the we.config file.
If both exists (enviroment variable and in the web.config - the one in the web.config win because it more specific)
<configuration>
<system.webServer>
<aspNetCore processPath="D:\Dev\Example.exe" arguments="" stdoutLogEnabled="false" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="443" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
To change the ASPNETCORE_ENVIRONMENT environmentVariable of the web.config while release there are some options, let me know if you want and I will post them.

Related

New Relic does not monitor my C# console application

I follow these steps to install and configure New Relic for my non-IIS .NET application: https://docs.newrelic.com/docs/agents/net-agent/instrumentation/instrumenting-non-iis-apps
Enable the agent in the application's config file. In the config file, add a new appSetting with a key named NewRelic.AgentEnabled and a value of true.
I have all done but couldn't monitor my app on New Relic.
Have any offer?
If you follow correctly all the steps newrelic has to work, make sure the following:
You activate the options in the red rectangles when you installed
(see this link http://i.stack.imgur.com/AroqR.jpg)
Create or modify app.config file of your application adding this (appSettings tag):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="NewRelic.AgentEnabled" value="true" />
<add key = "NewRelic.AppName" value="MYAPPLICATIONNAME" />
</appSettings>
In the new relic config file, make sure you are renaming the "instrumentation" tag with the name you use in app.config (NewRelic.AppName value)
<instrumentation>
<applications>
<application name="MYAPPLICATIONNAME" />
</applications>
</instrumentation>
Restart you application (or your windows session lol)
I did this a lot of time and works for me.

EF6 and MySQL Generate Database from Model

I've tried every solution I've found on the web with no success. I continually get the error:
Running transformation: System.InvalidOperationException: The SSDL generated by the activity
called 'CsdlToSsdlAndMslActivity' is not valid and has the following errors:
No Entity Framework provider found for the ADO.NET provider with invariant name
'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework'
section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for
more information.
I have an empty Console project and a very basic model to test this with. Through the NuGet Package Console I'd executed: Install-Package MySQL.Data.Entities which installed EF6, MySQL.Data and MySQL.Data.Entities and hooked up all the references and copied the relevant DLL's into the bin/Debug folder.
I wired up the provider in the following (entire config file listed)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
</providers>
</entityFramework>
</configuration>
As far as I can tell I have the provider registered. I have the latest MySQL connector updated as well. Where am I going wrong?
To support full functionality EF Designer requires 3 things:
EF runtime provider (you seem to have it)
DDEX provider for your database - DDEX is the way VS abstracts databases and as a result can talk to any database. Note that this is not something that is EF specific but EF Designer relies on it (again you seem to have it otherwise you would not be able to select MySQL connection)
Additional components (T4 templates/Workflow activities) required to support Model First flow - these are EF specific but typically installed as part of the DDEX provider - you seem to be missing this or you did not select the T4 template/workflow specific to your provider (open the edmx file and go to the properties window there are two options there that are interesting from DDL generation perspective - the "Database Generation Workflow" and the "DDL Generation Template". Click the dropdowns to see if you can select something that is MySQL specific)
Because you don't seem to have or use the workflow/T4 for MySQL (note I don't know if this is because you did not select the correct T4/workflow (see above) or MySQL DDEX does not support this or the installation is for whatever reason broken) EF Designer is using the default workflow which is for Sql Server. The default workflow relies on being able to find EF providers (for SqlServer and SqlServerCe) in the default path but the provider for MySQL is not there - hence the error. Note that the workflow and T4 templates for creating DDL are provider specific so even if you copied the MySQL provider to the default path it would not really work - you would get a peculiar result of SQL Server specific SQL Script using MySQL types.
We have a bug on improving this a little bit by providing a better guidance instead of just invoking the default DDL generation which we know will not work. You can also find some details in this bug.
I would suggest checking if MySQL components you are using do support Model First. An alternative would be just to move to Code First which only requires the EF runtime provider you already have to generate the DDL.
The other answer already kind of says this, but it's buried in his long post.
Notice that the error message refers to SSDLToSQL10.tt. You don't want that .tt file, you want the MySQL one. In the EF designer properties window, find the DDL Generation Template property and change it from SSDLToSQL10.tt to SSDLToMySQL.tt.

In my server saying "Could not load file or assembly 'MySql.Web..." but I have mysql in my application

Parser Error Message: Could not load file or assembly 'MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
...
Line 240: <providers>
Line 241: <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.7.4.0,
.....
Resolved to putting the tag in the web.config file the following line:
<remove name="MySQLMembershipProvider"/>
I do not have access to the server settings to remove mysql. But there is another way to solve this that does not happen again?
I got this error when deploying a website to the server (but not when debugging).
To fix it, select References -> MySql.Data and set the Copy Local parameter to True. When deployed on the server you can verify this by the presence of the MySql.Data.dll in the bin folder.
Actually I believe if you remove or comment out the line with
<add name="MySQLRoleProvider" />
see http://forums.asp.net/t/1928379.aspx for more details.
This error appears in general when you provide the DLL-File in the wrong CPU-Type. So maybe you supplied x86 but you need x64. But I'm not an expert in web-development. I know this error from developing .net-Services.
secure_file_priv may be set as follows:
If empty, the variable has no effect.
If set to the name of a directory, the server limits import and export operations to work only with files in that directory. The directory must exist; the server will not create it.

Using ASP.NET with MySQL as default database?

Im creating a ASP.NET site, but i dont want to use SqlServer i want to use my pre-existing MySQL database as the default connection. ive set up a new schema for it and assigned a user, and changed my default connection string to this
<add name="DefaultConnection" connectionString="Server=THEIP;Database=THESCHEMANAME;Uid=THEUSER;Pwd=THEPASSWORD;" providerName="MySql.Data.MySqlClient" />
It seems to be able to connect to the DB alright (as far as i can tell?)
so now i figured i needed to change the default membership provider so that the login is ran through this connection, i did some looking around on the net and found this on the MySQL site
<add name="DefaultMembershipProvider" autogenerateschema="true" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="DefaultConnection" />
So i replaced my default membership provider with this, ran the site from Visual Studio, went to /Account/Register.aspx (every other page works alright as of yet) and i get this error
Could not load file or assembly 'MySql.Web, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Can anybody point out what ive done wrong?
The version of the assembly was wrong, i went into the refrence assemblies and found that the version is not '6.0.4.0' but is infact '6.6.5.0', changed the version no. and its all working fine now.

Shared Hosting + Entity Framework + MySQL = Data Provider Errors?

long-time listener, first-time caller!
I’m trying to connect to MySQL using the ADO.NET Entity Framework. (Visual Studio 2010, .NET 4.0) I created a web project and another class library project to serve as my DAL. On my local machine, I have no problems, and I have also tried running with Medium trust. I’m able to fully control the db as expected.
When I deploy to my host (shared, medium trust) however, I keep getting errors. I have tweaked my web.config multiple ways: I’ve explicitly called my assembly in the connection string, I’ve used the wildcard mapping, I added references to the MySQL dll’s, etc.
<connectionStrings>
<add name="NamespaceContext" connectionString="metadata=res:// Namespace.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/DataModel.csdl|res:// Namespace.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/DataModel.ssdl|res:// Namespace.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null/DataModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=myserver;User Id=user;database=thedatabase;password=password;Persist Security Info=True"" providerName="System.Data.EntityClient"/>
<add name=" NamespaceContext " connectionString="metadata=res://*/;provider=MySql.Data.MySqlClient;provider connection string=" server=myserver;User Id=user;database=thedatabase;password=password;Persist Security Info=True"" providerName="System.Data.EntityClient"/>
<add name=" NamespaceContext " connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=MySql.Data.MySqlClient;provider connection string=" server=myserver;User Id=user;database=thedatabase;password=password;Persist Security Info=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
The error I keep getting is:
System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. --->
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
--- End of inner exception stack trace ---
at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at MyNamespace.Web.Html.TestPage.EntityFrameworkTestButton_Click(Object sender, EventArgs e)
I talked to their support guys (who aren’t devs) but they said the MySQL connector is installed and in the GAC. I tried to use the DbProviderFactories section in my web.config, like the following:
<system.data>
<DbProviderFactories>
<clear/>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
I was hoping I could control this and reference the provider in my project. I then receive the following error:
System.Data.MetadataException: Schema specified is not valid.
Errors: error 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.
MySql.Data.Entity.Properties.SchemaDefinition-6.0.ssdl(4,9) : error 0169: All SSDL artifacts must target the same provider. The ProviderManifestToken '5' is different from '5.0' that was encountered earlier.
error 0194: All artifacts loaded into an ItemCollection must have the same version.
(lots of the same error message was snipped for brevity)
I am at a complete loss. I tried strongly signing my DAL project, not using a DAL and just creating the .edmx in the web project, all to no avail. I could have sworn I got it working at some point, but perhaps I was delirious.
Sorry for the wall o' text. Can anyone help or shed some light?
Thanks!
What happens if you put the mysql dll in your bin folder? Alternatively, try to remove the version restriction on the mysql dll, they may not have that exact version loaded on their servers.
I had a very similar problem in my application, where I was using the MySQL connector for a MySQL database and the Entity Framework for a SQL Server database (two separate connections, one project). The MySQL.Data.Entity DLL seems to fight with the entity framework. I didn't actually need it so I removed it... but the error persisted!
Finally out of desperation I just deleted my bin and obj folders and recompiled. Problem solved. I guess something was cached or hanging around in my folders, even after I ran a clean and rebuild. Something to try anyways if someone else runs into this.