I have a project that has 3 layers.
1)Interface (It is an MVC project with View and Controller)
2)BI (It is a class library project)
3)DAL (It Is A class library that work with Entity Framework DataBase First)
My Problem :
There is a connection string in webconfig of the first project(MVC). But I want remove it. then the other layers should use of DAL Connection Strings.
But when I delete the connection string from that it cant connect and work with DB !!
I remember when I was working with ASP.NET and Linq to sql it was posible.
Please help me.
Once deployed, the only configuration that will be available will be the web.config of your MVC project. Instead of removing the connection string you could just encrypt it.
ASP.NET Connection String Encryption / Protection
Programmatically encrypting a config-file in .NET
http://msdn.microsoft.com/en-us/library/89211k9b.aspx
Personally I'm using a mechanism based on that blog post. I have an administrative api call on my web application to send the information that must be encrypted.
- http://weblogs.asp.net/sukumarraju/archive/2009/09/28/encrypt-and-decrypt-connectionstring-section-in-web-config.aspx
Related
I am using Visual Studio 2013. Unfortunately I am facing some problems with my MVC project. So I created a new project and I need to fetch database to my new project but can't figure out how to fetch database. I am using data first approach, entity framework and IIS Express localhost.
Update:
I copied connection string from web.config of old project and pasted it over new project's connection string.(Note I first created ado.net entity data model in new project and then pasted string over its connection string).
Now in server explorer window > data connections my Entities connection has changed to defaultconnection and I get exception The underlying provider failed on Open on executing query of new projects database. But I am unable to fetch old database tables.
Your DBContext likely has the name of the database connection in one of it's constructors.
This corresponds to the name of a connection string the web.config.
So move that configuration to your new web config and make sure your new DbContext references the correct name.
I created a mvc5 asp.net website that connects to sql server database. Looks like when ever I register a user through this website, user is created to database called DefaultConnection that is located at C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA.
But my config file is not pointing to this. My config file is pointing to a proper database at certain server. Also my connection has different name like
<connectionStrings><add name="TestEntities"....
And when I run my website it correctly bringing info from this database. Problem is only when I register a user.
The membership provider doesn't know to use a connect string named TestEntities, by default it uses a connection string named "DefaultConnection" and seemingly has a fallback in case that isn't present.
(See this to be more precise: ASP.NET Configuration File Hierarchy and Inheritance)
You could:
change your connection string name to DefaultConnection
copy your connection string and call the copy DefaultConnection
override the connection string name used by Entity Framework under the hood using the config below. I believe you can also override the connection string name used by creating you own DBContext.
Personally, I'd go with option 2, provides flexibility if you ever want to move the user tables out to a seperate database.
I can't find the exact issue I have on here or anywhere.
I have an ASP.Net MVC WebApi (MVC 5.1.0, Framework 4.5.1) project that uses Oracle.DataAccess. It runs on the local IIS server via a URL that's in my hosts file. It has a connection string connecting to an Oracle database. It works fine.
I have a 'normal' ASP.Net MVC (MVC 5.2.2, Framework 4.5.2) project that uses Oracle.ManagedDataAccess and Dapper. It runs on the local IIS server via a URL that's in my hosts file. It uses the SAME connection string (barring the providerName) to (attempt to) connect to an Oracle database. it does not work, throwing
ORA-12154: TNS:could not resolve the connect identifier specified
when I try to open the connection.
<add name="OurName" connectionString="Data Source=xxxxx_migration2;Persist Security Info=True;User ID=OurUserName;Password=thepassword;Enlist=False;Min Pool Size=10;Connection Lifetime=120;Connection Timeout=30;Incr Pool Size=5;Decr Pool Size=2;" providerName="Oracle.ManagedDataAccess.Client"/>
TNSNames.ORA is fine [as you'd reckon given that the exact same connection string works in the other project], there are no brackets in the project file paths (a very obscure issue I found in my researches), ORACLE_HOME is pathed... I am stumped.
I know Dapper extends the connection object - does it have any really funky weird requirements that might be causing this?
EDIT: If I switch the 'normal' ASP.Net MVC (and connection string providerName parameter) to Oracle.DataAccess, and don't use Dapper I can connect.
In the end, I needed to make more config file changes than I thought, in order to make Oracle.ManagedDataAccess work (Dapper was not an issue).
see this blog article
and the accepted answer here
It's a little bit annoying, and a change from the past situation to have to manually specify the location of TNSNAMES.ORA in the config file - but hey, it's a config file after all.
In my case, in Web.config file, oracle.manageddataaccess.client -> dataSources tag, alias name was wrong. Once changed, it worked.
When using a separate project to handle db operations in an mvc project, should I store the connectionstring in the dbproject (using app.config) or should I keep the connectionstring in the web.config of the mvc project, and inject it into the repository (provided by the dbproject) when instantiating it?
The config is always read from the outermost app. The web.config is where your connectionstring should be.
You can read it from your db project just as if it were the main project. You don't need to inject or do anything special.
I've built a backend in ASP.NET MVC2 which has an underlying ADO.NET Entity-based Database.
In the MVC Backend, I call my database entities, i.e.:
Entities entities = new Entities();
...and that all works fine.
Unforutnetly, in my Azure/mvc2 project, My worker role makes the azure project throw weird exceptions:
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."
Any ideas ladies and gentlemen?
Solved it myself - it was a PEBKAC issue.
Had to manually set the configuration string in the Worker role's App.config (Copypasted from from the ASP/NET MVC2 Project's Web.config).
All works well now.