0

I've the next error in my sql server's connection to visual studio:

ArgumentException: The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers.

The code in my app.config file is:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="SQL_Connection"
         connectionString="Data Source=DESKTOP-ROTBMUO;
          Initial Catalog=johnsonControls;
          Persist Security Info=True
          User ID=DESKTOP-ROTBMUO\Macbook Pro;"
         providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

And the error that shows me in my index.cshtml page is the next one:

@using WebMatrix.Data;
@{
    var db = Database.Open("SQL_Connection");
    var queryShow = "EXEC verLineasYAreas";
    foreach (var row in db.Query(queryShow)) {
        @row.nombre;
    }
}

I don't know if I've to install some packeage called System.Data.SqlClient just like I did with Web.Matrix or if the problem is in my or in my foreach. I hope you guys can help me, or if you've one better way to do a connection I'd like to see it!

  • 1
    Accessing database in your view should be avoided at all times – Preben Huybrechts Jul 08 '20 at 18:27
  • Where should I do the connection? – Jose Luis Garcia Jul 08 '20 at 18:49
  • In your controller(s) or in repositories – Preben Huybrechts Jul 08 '20 at 18:51
  • I think that my problem is in the connection, I’ve just try another way to show my information but the error is the same. http://blog.johnavis.com/blog/726/using-webmatrix-data-in-asp-net-web-forms/ – Jose Luis Garcia Jul 08 '20 at 19:38
  • If you're using .NET Core then you probably want to use Microsoft.Data.SqlClient instead of .NET Framework's System.Data.SqlClient. Depending on your project type you'll need to install the Microsoft.Data.SqlClient package with NuGet (only a few project types include it by default). – AlwaysLearning Jul 08 '20 at 22:14
  • Here is a same question which you can refer to : https://stackoverflow.com/questions/52007836/dbproviderfactories-getfactoryclasses-returns-no-results-after-installing-net-s – LouraQ Jul 09 '20 at 08:00

0 Answers0