0

I have created a Web API built on .NET Framework 4.7.2. I want to be able to communicate with SQL Server without using Entity Framework.

Microsoft.Data.SqlClient and System.Data.SqlClient are not compatible with .NET Framework 4.7.2. I really do not want to use any ORM.

Any suggestions?

3
  • 3
    SqlConnection and related classes are built into .NET Framework, you don't need to add anything. Commented Nov 6, 2020 at 20:29
  • 2
    ADO.NET, in System.Data.SqlClient Commented Nov 6, 2020 at 20:31
  • System.Data.SqlClient does not work with .NET Framework4.7.2. Here is the information on that. github.com/dotnet/efcore/issues/14880 - System.Data.SqlClient 'not supported on this platform' on Framework 4.7.2 Commented Nov 6, 2020 at 21:37

2 Answers 2

1

You can use dapper for example:

var data = new List<DapperTest>();
        using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["Analysis"].ConnectionString))
        {
             data = db.Query<DapperTest>("select * from testTable").ToList();
        }
        return data;
Sign up to request clarification or add additional context in comments.

3 Comments

So I stated that I did not want to use an ORM. Also, I see that your code is utilizing SqlConnection which is exactly the problem I am running into. As stated above System.Data.SqlClient, which provides SqlConnection object, is not available in .net framework 4.7.2.
github.com/dotnet/efcore/issues/14880 - System.Data.SqlClient 'not supported on this platform' on Framework 4.7.2
Okay, I just checked Microsoft documentation and It clearly shows it still included. I don't understand why my application cannot see the SqlConnection object. I have System.Data.SqlClient in my using statements and everything.
0

I figured it out. I build a .net Standard library instead of a .net Framework library.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.