data.sqlclient

DonaldJamesParker 31 Reputation points
2022-08-29T21:14:25.9+00:00

I retired from programming 10 years ago (as a career). I got a wild hair up my nose this weekend and downloaded Visual Studio 2022 Community. I spent the majority of yesterday and today trying to simply get access to the Data.SQLClient object. I wrote a console application that worked just fine. When I tried to create a win forms project or a class library, I found that the System.Data.SqlClient object only had two subobjects. In researching this I discovered that System.Data.SqlClient has been replaced by Microsoft.Data.SqlClient but I don't have that namespace in Visual Studio. I've tried to install the package in various ways and have had no success. I'm about ready to punch out my monitor and go back to VS 2012 Express. The whole situation with multiple versions of the framework coupled with multiple version of net.core and now the seeming marriage between the two is more confusing than Who's on First. Call me crazy but it seems to me that if I download Visual Studio, that all the assemblies I need would be included in that installation. I turns out that the only projects I can get to work are the ones that allow me to choose an older framework. WinForms application only give me the options for .net 5, .net 6, .core 3.0 and .core 3.1. None of those worked. Can anyone preserve my sanity here and tell me how I can get Microsoft.Data.Sql available in my .net 6.0 projects?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,489 questions
0 comments No comments
{count} vote

Accepted answer
  1. Jack J Jun 24,276 Reputation points Microsoft Vendor
    2022-08-30T09:47:43.807+00:00

    @DonaldJamesParker , Welcome to Microsoft Q&A, based on my test, I find that I can used System.Data.SqlClient and Microsoft.Data.SqlClient normally both.
    SqlClient is only a namespace and not a class.

    Please try the following steps to use the reference in .net 6.0 project.

    First , Please install nuget-package System.Data.SqlClient.

    Second, Please add the using statement:

    using System.Data.SqlClient;  
    

    Finally, you could try the following code to check if the code works for you.

    SqlConnection connection = new SqlConnection("connstr");  
    connection.Open();  
    

    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. DonaldJamesParker 31 Reputation points
    2022-08-30T17:01:20.51+00:00

    Here's the deal. I could not get NuGet to work for me. Visual Studio 2022 came with only one source provided for Nuget and that was a reference to the Program Files (86) folder on my hard drive. I could not find what the correct address was for Nuget. After reading your page YogiYoyi, I saw the instruction to use NuGet to install the package. I hadn't even seen the reply JackJJun's answer yet. Turns out you both helped me. I ran across a page on GITHub that actually showed the Source list for Nuget and got the correct address for their library: https://api.nuget.org/v3/index . I updated my source list and installed both System.Data.SqlClient and Microsoft.Data.SqlClient successfully. I was about to go crazy with these problems. Why VS didn't have the Nuget address in the source collection for the Package Manager, I have no idea. Since I had not even heard of Nuget until 2 days ago, I had no idea what I was doing. Thanks so much for your input. Now I can start programming again instead of beating my head against a wall.

    1 person found this answer helpful.

  2. Yogi 346 Reputation points
    2022-08-30T12:42:48.277+00:00

    Kindly refer this tutorial on ADO NET which uses DOT NET 6.0 version - Learn ADO.NET by building CRUD Operations in ASP.NET Core.
    The full source codes are available for download so you will not have any problem.

    0 comments No comments