I have a fresh Visual Studio 2017 Professional install. I'm building a quick POC Console application using .NET 4.7.1, and I'm unable to find the reference for System.Data.SqlClient.
I have scoured my system, and located 4 versions of System.Data.SqlClient.dll, but none are correct and won't compile. I have also attempted to use System.Data, but no reference to SqlClient is located within. I have manually added the dll/reference for System.Data, but also did not resolve the reference issue.
My application is really simple at the moment, and it will NOT compile due to this missing reference.
What steps do I need to do to get this resolved?
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApp1
{
class Database
{
public void Start()
{
string connString = @"server=(local);initial catalog=MyDatabase;Integrated Security=SSPI;";
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 ID, Name FROM TableA", conn))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
Console.WriteLine("ID: [{0}], Name: [{1}]", reader.GetValue(0), reader.GetValue(1));
}
}
}
}
}
}
}
dotnet add package System.Data.SqlClient
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With