Skip to content

VS Designer support for Microsoft.Data.SqlClient #1297

Closed

Description

@abbfmst

I need help migrating an existing .NET 4.8 WinForms desktop app from System.Data.SqlClient to Microsoft.Data.SqlClient.
I've done all the steps as outlined in the porting cheat sheet:

  • Replaced 'System.Data.SqlClient' with 'Microsoft.Data.SqlClient' (yes, not only the 'usings', see why below)
  • Added the DbProviderFactory element to App.config

Yet when I open a DataSet and select a TableAdapter, its Connection property always says "Unable to find connection '...' for object 'Settings'. The connection string could not be found in application settings, or the data provider associated with the connection string could not be loaded"

So I started with a new simple prototype and made the exact same steps.
You can find it attached here.

Here's what I did:

  • Create new .NET 4.8 WinForms desktop application
  • Create a new SQL Server database 'Database1' with table 'Table1' with column 'Column1' and a parameterless stored procedure 'USP1' doing 'select Column1 from Table1'
  • Add a DataSet
  • Add a TableAdapter with a new Connection with a 'Fill()' method invoking USP1
  • Add a Form1 with a DataGridView and a BindingSource bound to the dataset
  • Create a new custom System.Data.SqlClient.SqlConnection and assign it to dataSet1.Connection (this is because in our productive application, the connection depends on the user environment obviously)
  • Run the project => Works fine, shows the form with the data of Table1

Now the migration:

  • Add a reference to Microsoft.Data.SqlClient NuGet version 3.0.1
  • Press CTRL+H in Visual Studio and replace all occurences of 'using System.Data.SqlClient;' with 'using Microsoft.Data.SqlClient;'
  • Add the DbProviderFactory element to App.config

Problem 1:
The connection cannot be re-assigned anymore as TableAdapter.Connection is of type System.Data.SqlClient.Connection, but we want to assign a Microsoft.Data.SqlClient.Connection.

So I press CTRL+H again and replace all occurences of 'System.Data.SqlClient' with 'Microsoft.Data.SqlClient'.
Now I can assign the connection, but...

Problem 2:
The dataset cannot be generated again with 'Run Custom Tool'. MSDataSetGenerator fails with System.Data.Design.InternalException.

=> What is the correct attempt to migrate this attached project?

Thanks for your help

MSDataSqlClientTest.zip

Activity

  1. ErikEJ commented on Sep 28, 2021

    @ErikEJ
    Contributor

    The visual studio designers are not aware of Microsoft.Data.SqlClient, so only way for now is your solution to problem 1.

  2. abbfmst commented on Sep 28, 2021

    @abbfmst
    Author

    Thank you @ErikEJ. Oh no that's too bad.

    Is there any plan or even a schedule for VS Designer support for Microsoft.Data.SqlClient?

    What would you recommend for an existing (huge) project full of DataSets/TableAdapters?

  3. cheenamalhotra commented on Sep 28, 2021

    @cheenamalhotra
    Member

    Is there any plan or even a schedule for VS Designer support for Microsoft.Data.SqlClient?

    We have communicated the same to respective teams who own VS Designer, if we receive any update we'll share. But as of now VS Designer & editor are unsupported for Microsoft.Data.SqlClient.

  4. changed the title [-]Migration issue - MSDataSetGenerator fails with InternalException[/-] [+]VS Designer support for Microsoft.Data.SqlClient[/+] on Sep 28, 2021
  5. added
    External 🔗
    on Sep 28, 2021
  6. abbfmst commented on Sep 29, 2021

    @abbfmst
    Author

    Thank you @cheenamalhotra
    To be honest, a quick mention of this rather important fact would have been nice in README.md and in the FAQ.
    Could you please add such a note?

    Do you know about any UserVoice entry or another channel where we can also reach the VS dataset Designer team and +1 the request?

  7. cheenamalhotra commented on Sep 29, 2021

    @cheenamalhotra
    Member

    We will document it soon.

    We reached to them internally, so there is no public facing conversation. You could, however, open a feature request with them on Developer Community and link it here for other community users to follow and upvote.

  8. abbfmst commented on Sep 30, 2021

    @abbfmst
    Author

    Done: https://developercommunity.visualstudio.com/t/vs-designer-support-for-microsoftdatasqlclient/1543400

    Let's hope this gets fixed soon. We'd really like to migrate to Microsoft.Data.SqlClient in order to move on to .NET Core.

  9. ErikEJ commented on Sep 30, 2021

    @ErikEJ
    Contributor

    Or maybe stop depending on the VS designers?

  10. abbfmst commented on Sep 30, 2021

    @abbfmst
    Author

    I fully agree Erik and definitely do so whenever possible.

    But what to do with active existing applications? The one in question here is in active development since 2006, updated from .NET 2.0 all the way up to .NET 4.8, still using Datasets and table adapters invoking stored procedures. Replacing them all with Dapper or something else wouldn't be trivial.
    Microsoft has a pretty good track record of being backward compatible or having a low effort migration path. After all, even the WinForms GUI part of this application is already running on .NET Core. I never would have thought they'd be able to support that.

  11. ErikEJ commented on Sep 30, 2021

    @ErikEJ
    Contributor

    Got it - System.Data.SqlClient works fine with .NET Core (depending on your feature requirements, of course)

  12. roji commented on Sep 30, 2021

    @roji
    Member

    @abbfmst I'm not an expert, but AFAIK the VS designer isn't required in any way in order to use DataSet, DataAdapter or stored procedure - there shouldn't be any need to replace anything with Dapper. Of course, it's still desirable to have the designer support Microsoft.Data.SqlClient, but it's important to understand that it's just a GUI - existing code should run fine and can still evolve.

  13. abbfmst commented on Oct 11, 2021

    @abbfmst
    Author

    @roji Please see the steps I mentioned above or check the attached prototype application.
    Either the type for TableAdapter.Connection is wrong or (if you refactor/rename it all) the DataSet generator fails.

    So yes, it's a GUI, but also a code generator tool. Existing code runs fine, but cannot be regenerated or evolve anymore.

  14. dzsquared commented on Jan 20, 2022

    @dzsquared

    Done: https://developercommunity.visualstudio.com/t/vs-designer-support-for-microsoftdatasqlclient/1543400

    With the VS Feedback item filed, the issue here can be closed and those who are looking for updates can follow the VS Feedback item.

  15. JRahnama commented on Jan 21, 2022

    @JRahnama
    Contributor

    thank you @dzsquared .

    Closing the issue as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    External 🔗

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions