I have an ASP.NET MVC web application working with Entity Framework and I have the same database schema in two different database engines (Oracle and MySQL). The database is the same in Oracle and MySQL. The application should work with this two providers because I have two different scenarios.
When I want to work in the Oracle Scenario I have to change manually the Web.Config to put the correct ConnectionString, the correct provider for member authentication, roleManager ..., and I have to delete the Database Model (edmx file) and recreate it for Oracle.
When I want to change working from Oracle to MySQL I have the same problem. I have to change the web.config to put the correct providers and the connection string and I have to recreate the database model (edmx file) for MySQL model.
Is there any way to avoid this heavy and boring task every time that I want to change the database?
Basically it is possible to create multiple Web.config and to automatically select the right one depending on the current used environment.
Additional information can be found here.
Related
My client asked to build an API in ASP NET Core for a business management application. Nonetheless, he made me an unusual requirement for me: He needs each user to have their own database. All databases have the same structure of tables and relationships and all are MySql.
This means that each user will need their own connection string and some way to store that information.
In addition, other users will be added in the future, each with a bank created just for their use.
Anyway, I don't know if this is possible, but if it is, how would I do it?
My project is an ASP.Net MVC Website that has been deployed to multiple customers, and each customer has their own SQL Server database. As you'd expect, the data in each database is different, so even in development we have separate databases for each customer. The database schemas are identical. We have a custom database context extending DbContext and managed by Unity.
Currently we switch between these databases by either renaming the databases themselves, or editing the connection strings in Web.config (technically in ConnectionStrings.private.config, which we pull into Web.config using a configSource attribute).
How can I develop the same codebase against multiple customer databases at once, without editing any configuration when switching database? For example, I might have one customer at http://customerone.localhost/ and another at http://customertwo.localhost/ (different port numbers would be OK too). Each accessing their own database but sharing the c# code.
In apache I can use <If> or SetEnvIf to set configuration based on the url, but there doesn't seem to be an equivalent in IIS. When I try to change it in c# code I am told it is read only.
To be clear I don't want any changes to be written back to web.config - I just want the custom database connection string to be used for the life of the request.
Using MVC3, VS 2010 and SQL Express, I have been successful getting through a few tutorials. What I'd like to do now is build my own app which will be deployed. Using Code First, I'd like to have my user authentication and data reside in the same database. From what I've read, it is possible, (acceptable?) but so far I have not found any info on how to get my models and membership to map to the same database - I would like to specify a different DB than aspnet.mdf.
For the membership tables you can use the aspnet_regsql.exe tool on the command line.
Specify the database and credentials and it will create the membership tables on that database.
You can point the Entity Framework to the same database.
This way, both membership and EF will be living in the same database.
I am currently working on a ASP .Net MVC 3 application to do some database manipulations on a specific set of Metadata tables in a database. I'll basically be doing inserts, updates deletes etc. from the application. However, the aim is to migrate these Metadata tables across different databases (and most likely servers as well) so that we can use the same Methodology across clients.
Right now I am using Linq2Sql to generate my ORM around these specific metadata tables. The aim is to use the same application to manipulate the data across servers and databases. What is the best practice/approach for this?
The simplest solution that I've thought of is a constructor for my DataContext where I could use user input (server + database name +userID +password) to manipulate a connection string and pass it into my DataContext. Since the Framework should be the same across all databases and servers, this should work in theory. However, I'm not where the best place to maintain the modified connection string is (The session? a cookie?).
What is the best practice around this kind of server/database switching in a .Net app?
You're going down the right path by passing the connection in the constructor for the context. As for maintaining the connection string, I suspect that would depend on how you are managing the other site information for your various sites. If you are managing that in a central database, save the site specific value in that central database and use the same persistance you are using for those site settings while the user is visiting your site. Just make sure not to pass server specific information to the client (thus a cookie would not be the recommended approach).
I have a client application (WPF, C#, .net4) which uses POCO entity model connected through SQLITE provider. So I want to have same entities from this project in an asp.net project (with MSSQL provider), to use there the same entities that I use in my client application. I want to create some kind of replication functionality between my client app (SQLITE) and web server (MSSQL) using same poco model using web services.
So I have a reference to my entities model in both projects with different connection strings for edmx files. And in this case (because edmx was compiled for sqlite provider) when I'm trying to use mssql data provider I get an exception:
unable to cast System.Data.SqlConnection to System.Data.SQliteConnection
So my question is if it is possible to use different data providers in one entities model?
What is the best way to use same model in different projects?
If I understand your question correctly, then if you are looking for your EF model to support multiple database implementations then this is not possible out of the box. The SSDL file auto-generated by EF will contain provider specific metadata and therefore will restrict its independence from the different database implementations you are using.
There are some articles out there providing ways around this, but this requires a separate copy of your model for each provider and hacking the generated XML with the provider details.
with POCO it should be possible.
As long as web service is passing xml or json data, it will not be bound to any specific data connector implementation. I am not sure what it will be in binary mode - possibly there's some link to data model.
Are you getting this error from WPF app or from web service? It sounds like you are trying to test this inside client app still. Did you try implementing web service yet?