Cannont implicitly convert type 'Microsoft.Data.SqlClient.SqlConnection' to 'System.Data.SqlClient.SqlConnection'

547 Views Asked by At

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.

0

There are 0 best solutions below