Hello all:
I'm building an app using C#/MVC3/Razor which has a database configured in web.config. One of the requirements is to push the data to another database. is this doable within the MVC3 framework or should i just connect to the second database using standard methods/sql/?
thanks
You could have a second connection string in your web.config and configure your ORM framework or whatever you are using to access those databases to use this second connection string:
<connectionStrings>
<add name="db1" connectionString="Data Source=serverName;Initial Catalog=dbName1;User Id=foo;Password=secret;" providerName="System.Data.SqlClient" />
<add name="db2" connectionString="Data Source=otherServerName;Initial Catalog=dbName2;User Id=bar;Password=secret;" providerName="System.Data.SqlClient" />
</connectionStrings>
Just one thing to remember: the ADO.NET Connection Pool is per App Domain and per connection string meaning that two separate connection pools will be held in this case.
<connectionStrings>
<add name="First_DB_Conn" connectionString="" providerName="Some_Provider" />
<add name="Second_DB_Conn" connectionString="" providerName="Some_Provider" />
</connectionStrings>
This way you can add more connection to another dbs
ASP.NET MVC itself contains nothing about databases (or any form of underlying persistence layer). In the MVC3 tools update some tooling for developers does make direct use of Entity Framework 4.1's "code first" capabilities.
But this is can be customised (eg. your own T4 templates or different scaffolding or completely ignored (manually write all persistence logic). The latter would be needed if your application doesn't map to CRUD operations that the scaffolding assumes.
Doing it yourself could use multiple ADO.NET connections (with multiple connections strings in the .config file) or multiple ORM models for different databases.
Related
I have an asp.net core web application using the ABP Boilerplate framework. I've implemented Abp.HangFire.AspNetCore HangFire into the application. The web application has a database for the application's data. And by default, the HangFire database tables were created in the same database where the application's data resides.
We were wondering about using a separate database for HangFire. Are there any implications in doing that? Can that be done?
Change the db connection to your separate hangfire database in your host project.
GlobalConfiguration.Configuration.UseSqlServerStorage("<name or connection string>", options);
Check out for more infos:
https://docs.hangfire.io/en/latest/configuration/using-sql-server.html
Abp.HangFire.AspNetCore reference only Hangfire.AspNetCore without Hangfire.SqlServer. In your Abp host project you could handle Hangfire.SqlServer like in any other ASP .NET Core (.NET 5) project.
https://github.com/aspnetboilerplate/aspnetboilerplate/blob/511ed6389052b3850cb4c6b8d833fb192ec030ac/src/Abp.HangFire.AspNetCore/Abp.HangFire.AspNetCore.csproj
Is there a way to deploy a single instance multi-tenant aware web api with specific configuration per tenant?
We have an Asp.net Web Api witch identify the tenant by claims inside a JWT but into the web.config are configuration per tenant. Example
<configuration>
<appSettings>
...
</appSettings>
<tenants>
<tenant key="1">
<add key="key1" value="false" />
</tenant>
<tenant key="2">
<add key="key1" value="value2" />
</tenant>
</tenants>
</configuration>
We dont use multi-tenancy in Octopus becose is only one installation per target but we cant imagine how to store and insert the configuration per tenant.
Any Ideas?
Full disclosure: I work for Octopus Deploy.
If I understand correctly you have a single binary that serves multiple tenants and web.config is used to specify which tenants are served by the application.
If so, then I would recommend splitting your application into 2 Octopus Projects. One which represents application code and one which represents configuration. The configuration Project would use multi tenancy in Octopus to add relevant entries to the web.config for each deployed tenant. This can be done using a config transformation or a custom script.
SO is a public forum so if you would like to share some sensitive information about your project then I would recommend you reach out to us via https://octopus.com/support.
Regards,
is it possible to use MVC6 without using EF?. Wanted to confirm as we have a huge application in .NET 4.0 WebForms which uses a custom BL layer and DB Layer to talk to multiple databases ( SQL Server & PostgreSQL) seamlessly.
Thanks in advance.
yes it's possible. EF is just help you to call database
Is there any chance to use ASP.NET Identity with Entity Framework while connecting to an Oracle database?
The challenge seems to be some version conflicts:
The Oracle Data Provider for .NET only targets Entity Framework 5 but not Entity Framework 6.
The NuGet package Microsoft.AspNet.Identity.EntityFramework targets EF6, not EF5.
It's not the code first feature that troubles me. It's getting the connection up and running and reading my user identity data from the Oracle database that bugs me.
Any pointers are much appreciated.
The solution is, of course, in implementing an UserStore class for the IUserStore (and IUserPasswordStore and IUserClaimStore and whatever one needs) interfaces.
Therein, it's just plain EF5 code that queries and updates the ASP.NET Identity tables.
Using this, the UserManager works just fine for accessing all identity data.
I'm trying to use LINQ with Npgsql 2.0.11 in a .NET v3.5 project. I'm trying my first simple query from a data table, and I've found that the syntax sent to Postgresql is SQL Server syntax, not Pgsql syntax, causing the server to throw a syntax error.
I have added the factory generation to the project's App.config as suggested by the documentation:
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"/>
</DbProviderFactories>
</system.data>
Here is a snippet:
DbProviderFactory factory = DbProviderFactories.GetFactory("Npgsql");
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = "Server=mydbhost.example.com;UserId=postgres;Database=postgres";
table = new DataContext(connection).GetTable<Project.Model.MyEntity>();
I've found that factory is an instance of Npgsql.NpgsqlFactory (seems right), and connection is an instance of Npgsql.NpgsqlConnection. All that seems good. However, when I attempt to GetTable, the SQL syntax generated contains square brackets and various other SQL Server specific syntax.
What could be missing?
DataContext
DataContext is LinqToSql. LinqToSql is for SqlServer only.
Perhaps you meant to use LinqToEntities and ObjectContext?
If one wants to use LINQ to SQL for RDBMS other than Microsoft SQL Server, a third-party assembly is required. DBLinq is a project that provides LINQ to SQL functionality for other (open-source) databases.
http://code.google.com/p/dblinq2007/
Npgsql can be configured as a db provider for Entity Framework following the documentation on this Npgsql blog:
http://npgsql.com/index.php/2009/08/how-to-set-up-entity-framework-npgsql-part-1/