0

I have a data set(.xsd) file I'm using in Visual Studio 2017 project and I've added a reference to 'Microsoft.Data.SqlClient' to it. In my constructor for a TableAdapter I have a line of code:

this._connection = new SqlConnection();

I get the error Cannont implicitly convert type 'Microsoft.Data.SqlClient.SqlConnection' to 'System.Data.SqlClient.SqlConnection'

I looked in the .Designer.cs file and noticed that everything uses the System.Data.SqlClient namespace.

ex. private global::System.Data.SqlClient.SqlConnection _connection;

From what I've read is that this namespace is on its way out and to use Microsoft.Data.SqlClient namespace for new projects.

Is there a way to make Visual Studio use Microsoft.Data.SqlClient in the designer file or am I stuck using the old System.Data.SqlClient?

I've also read not to edit .Designer files since VS auto-generates this code and will overwrite anything I add to it. So I don't want to manually change all the System.Data.SqlClient calls just have Visual Studio erase it and cause a bunch of errors.

  • 4
    What's *really* on its way out (or ought to be) is data sets. There are more effective solutions for typed data access these days, be it EF or Dapper. – Jeroen Mostert Jun 27 '22 at 14:53
  • "Is there a way to make Visual Studio use Microsoft.Data.SqlClient in the designer file or am I stuck using the old System.Data.SqlClient?" - probably not. The XML XSD Designer code in VS hasn't changed significantly since VS2005 (or even VS2003?). – Dai Jun 27 '22 at 14:55
  • @JeroenMostert `DataSet` and `DataTable` are still essential for runtime-defined data (e.g. executing user-defined SQL directly) - though I agree the use-cases for `DbDataAdapter` and the `Fill` methods are limited - the `UPDATE` statements they generate are all RBAW ops - it's easier to generate a `MERGE` from a TVP by-hand in that situation. – Dai Jun 27 '22 at 14:57
  • @Dai: yes, I'm specifically talking about the typed access layer VS generates on top of things. There are scenarios where `DataTable` has its uses even outside database tooling, though `DataSet` is less commonly useful still, and neither should be the *preferred* solution if it's at all possible to nail down the schema. – Jeroen Mostert Jun 27 '22 at 15:01
  • @JeroenMostert I have no idea what EF or Dapper is. Could you elaborate so I could look into this? – db_at_systems Jun 27 '22 at 15:05
  • 2
    EF is [Entity Framework](https://learn.microsoft.com/aspnet/entity-framework), Dapper is [Dapper](https://dapper-tutorial.net/dapper). Both are libraries for doing object-relational mapping (ORM) -- the problem of translating relational data to objects and back. EF is "big", Dapper is "small". They are of course not the only libraries for that, but arguably the most popular for .NET. Typed datasets also try to solve this problem, but in a way that more or less marries the worst of both worlds in terms of performance and abstraction, and the feature is not being actively maintained. – Jeroen Mostert Jun 27 '22 at 15:10
  • Do you mean to change the "Microsoft.Data.SqlClient.SqlConnection" reference in the project to "System.Data.SqlClient.SqlConnection"? – Housheng-MSFT Jun 28 '22 at 02:09

0 Answers0