1

I'm writing a website in ASP.NET 5 MVC 6 and need to setup a connection to a SQL Server database in order to retrieve some data.

Since I have many existing databases with a lot tables that I have to pull data from with small queries, I believe ADO.NET would be easier to work with than Entity Framework.

How should I go about implementing this in ASP.NET 5?

I've tried to follow this tutorial http://www.compilemode.com/2015/09/crud-operations-in-aspnet-mvc-5.html (it's for ASP.NET MVC 5) but at the EmpRepository I was getting errors about the ConfigurationManager not existing in the current context, although I had using System.Configuration; and a reference to the assembly. I've tried everything that was suggested in this The name 'ConfigurationManager' does not exist in the current context post. Same error still remains.

Is there another way of setting up a connection with ADO.NET using ASP.NET 5?

Community
  • 1
  • 1
Isac
  • 21
  • 4
  • Possible duplicate of [The name 'ConfigurationManager' does not exist in the current context](http://stackoverflow.com/questions/1274852/the-name-configurationmanager-does-not-exist-in-the-current-context) – Luizgrs Dec 01 '15 at 16:02
  • I think this question would help you http://stackoverflow.com/questions/32599573/how-do-i-inject-asp-net-5-vnext-user-secrets-into-my-own-utility-class/32608820#32608820 also I have a project here that is using traditional ado.net for data access and the code there may be instructive https://github.com/joeaudette/cloudscribe – Joe Audette Dec 01 '15 at 16:07
  • Have your read the doc on Configuration at https://docs.asp.net/en/latest/fundamentals/configuration.html ? – Pawel Dec 01 '15 at 18:13
  • Yes, I've read the docs, but I still can't get a grip on how to setup a connection :/ – Isac Dec 01 '15 at 19:45
  • basically you want to create a class that will have a ConnectionString property that you can configure in startup to be hydrated from one of the new config sources and you then can have the DI system inject an instance class into the constructor of the class where you need the connection string. No more static access to config. The question I posted previously and its comments has examples how to wire up the class and get it injected – Joe Audette Dec 01 '15 at 21:12

0 Answers0