dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

SqlDataAdapter is missing from NetStandard System.Data.SqlClient #27872

Closed divega closed 4 years ago

divega commented 6 years ago

From @EdLichtman on November 9, 2018 15:48

I'm attempting to build an utility library using NetStandard and I have installed System.Data.Common and System.Data.SqlClient. When I attempt to use a SqlDataAdapter I get the error "The type or namespace name "SqlDataAdapter" could not be found.

What am I supposed to do to resolve?

Copied from original issue: aspnet/EntityFrameworkCore#13929

divega commented 6 years ago

From @dallancarr on November 9, 2018 17:2

Add https://www.nuget.org/packages/Microsoft.Windows.Compatibility/2.0.0

divega commented 6 years ago

@EdLichtman can you please report this issue at https://github.com/dotnet/corefx/issues/new. That is were issues for the System.Data.SqlClient packages are tracked.

Also, I haven't tried that @dallancarr suggest but it seems worth trying. Even if it turns out the Microsoft.Windows.Compatibility pack helps, I am not sure that should be necessary, so it seems to be this is a valid issue.

divega commented 6 years ago

From @dallancarr on November 9, 2018 21:27

Should not be strictly required as @divega mentioned.

divega commented 6 years ago

From @dallancarr on November 9, 2018 22:2

Example here using netcoreapp.2.0 using preview version of the SqlClient library.

https://github.com/jhealy/aspdotnetcore/blob/master/SqlClientPlay20/SqlClientPlay20/SqlClientPlay20.csproj

divega commented 6 years ago

Keeping the issue open until next triage to make sure someone reports it to corefx.

divega commented 6 years ago

I don't fully understand why that would be the case, but this issue seems related to the compatibility shims mentioned in https://github.com/dotnet/corefx/issues/27247.

@EdLichtman or @@dallancarr if you are able to provide a repro project that shows the failure, that would be great.

I am not sure whether this is a bug in the SqlClient package (in https://github.com/dotnet/corefx/issues/27247#issuecomment-369522617 I asked @terrajobst if SqlClient should include its own compatibility shim), or an issue (or known limitation) with .NET Standard, in which case this may need to be moved to https://github.com/dotnet/standard/ or closed.

EdLichtman commented 6 years ago

@divega @@dallancarr I am currently on my home computer with Visual Studio with specifications I will provide in a separate message. I tried steps to recreate: Create new DotNetStandard 2.0 project. Install-Package System.Data.SqlClient. Attempt to create Database Facade class.

Oddly enough, I am unable to recreate the issue from my home system and am able to compile my code:

using System;
using System.Data;
using System.Data.SqlClient;

namespace SqlDataAdapterMissing
{
    public class DatabaseFacade
    {
        private readonly string _connectionString;

        public DatabaseFacade(string connectionString)
        {
            _connectionString = connectionString;
        }

        public T Fetch<T>(string sql, Action<SqlCommand> parameterize, Func<DataTable, T> parse)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(sql, connection))
                {
                    parameterize(command);
                    using (var adapter = new SqlDataAdapter(command))
                    {
                        DataTable table = new DataTable();
                        adapter.Fill(table);
                        return parse(table);
                    }
                }
            }
        }
    }
}

It seems it might be a problem with old version of Visual Studio? I will post the specifications for the known working version and the specs for my known not-working version for comparison, then I'll try to update my work machine VS2017 and if successful, I suppose the problem righted itself and the issue could be closed. I'll update you on Monday.

EdLichtman commented 6 years ago

Specifications of Working VS2017:

Microsoft Visual Studio Community 2017 Version 15.7.5 VisualStudio.15.Release/15.7.5+27703.2042 Microsoft .NET Framework Version 4.7.03056

Installed Version: Community

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

Application Insights Tools for Visual Studio Package 8.12.10405.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.40625.0 ASP.NET and Web Tools 2017

ASP.NET Core Blazor Language Services 0.5.1-rtm-10384

ASP.NET Core Razor Language Services 15.7.31476 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60618.0 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.0.40608.0 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.3.4000.4 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 15.9.02046.0 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.3.4000.4 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 2.8.3-beta6-63029-08. Commit Hash: e9a3a6c0ba5b1fde8b1fff964bdfb3fb768ee2eb C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 15.7.18156.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Fabric.ApplicationInsights 1.0 Allows user to instrument their Service Fabric projects for Application Insights.

Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events

JavaScript Language Service 2.0 JavaScript Language Service

JetBrains ReSharper Ultimate 2018.1 Build 112.0.20180414.70444 JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2018 JetBrains, Inc.

Microsoft Azure HDInsight Azure Node 2.3.4000.4 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.3.4000.4 Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 2.2 Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.3.4000.4 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10420.2

Microsoft Continuous Delivery Tools for Visual Studio 0.3 Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Python 15.7.18156.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support 15.7.18156.1 Provides templates and integration for the Django web framework.

Python - IronPython support 15.7.18156.1 Provides templates and integration for IronPython-based projects.

Python - Profiling support 15.7.18156.1 Profiling support for Python projects.

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61804.210 Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 15.7.20419.2003 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.8.3-beta6-63029-08. Commit Hash: e9a3a6c0ba5b1fde8b1fff964bdfb3fb768ee2eb Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.1 for F# 4.1 15.7.0.0. Commit Hash: 173513e369ffb7a1c4d5dccf83696d9aac2ab2d0. Microsoft Visual F# Tools 10.1 for F# 4.1

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

EdLichtman commented 5 years ago

Closing issue since I'm unable to recreate. Maybe it was a turning it off and on again issue. Maybe it was Resharper installing the wrong version of System.Data.SqlClient, but at this point my brand new solution following the same steps to recreate on my work machine is compiling without issue.

EdLichtman commented 5 years ago

I can't find the normal close issue button. Is this a permissions thing or am I not looking hard enough? If it's a permissions thing, please close this issue since it appears to already have been fixed at some point.

keeratsingh commented 5 years ago

Closing issue as the original author @EdLichtman is unable to repro.