question

DonaldJamesParker-5652 avatar image
1 Vote"
DonaldJamesParker-5652 asked yogyogi commented

data.sqlclient

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?

dotnet-sqlclient
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JackJJun-MSFT avatar image
1 Vote"
JackJJun-MSFT answered JackJJun-MSFT edited

@DonaldJamesParker-5652, 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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks!! See note below!! I'd accept your answer but it doesn't give me the option to do so.

0 Votes 0 ·
JackJJun-MSFT avatar image JackJJun-MSFT DonaldJamesParker-5652 ·

@DonaldJamesParker-5652, thanks for the feedback, I have converted my comment to answer. You can do it.

1 Vote 1 ·
yogyogi avatar image
0 Votes"
yogyogi answered yogyogi edited

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DonaldJamesParker-5652 avatar image
1 Vote"
DonaldJamesParker-5652 answered yogyogi commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

glad to help you. Enjoy coding!

0 Votes 0 ·