Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install the System.Data.SqlClient

I am trying to create Web API that will connect to the SQL server and run the stored procedure. I wanted to install the System.Data.SqlClient in to the project so I can give the connection details. But when tried to install that through the Nuget Manager it throws error like

 Install failed. Rolling back...
 Could not install package 'System.Data.SqlClient 4.3.0'.
 You are trying to install this package into a project that targets. 
 '.NETFramework,Version=v4.5', but the package does not contain any 
 assembly references or content files that are compatible with that 
 framework. For more information, contact the package author.

How can I install them or is there any other way of giving the connectionStrings in web.config

like image 758
user4912134 Avatar asked Mar 02 '26 01:03

user4912134


1 Answers

I could solve this problem with a little workaround for Xamarin PCL:

  1. Change your PCL target to .NetStandard. You can do it in the PCL project properties.
  2. Create a new .NetStandard ClassLibrary project.
  3. Add the System.Data.SqlClient and your code
  4. Reference the ClassLibrary project dll to the PCL project
  5. With this library you can use the SqlClient.

In your case with asp.net: Perhaps, you can try to create a .NetFramework ClassLibrary and follow the steps above.

I hope it will help you!

like image 124
Sean Stayns Avatar answered Mar 04 '26 15:03

Sean Stayns



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!