Exception when using Microsoft.Data.Sqlclient Ado.net with project .Net core 6.0 project library

529 views Asked by At

I have an exception when I use sql.data.client to query database sqlserver :

system.platformnotsupportedexception microsoft.data.sqlclient is not supported on this platform

My code source :

using (var connection = new SqlConnection(connectionString))
    {
        using (var cmd = new SqlCommand(queryString, connection))
        {
              cmd.Connection = connection;
              connection.Open();

              using (SqlDataReader reader = cmd.ExecuteReader())
              {
                   while (reader.Read())
                   {
                       return true;
                   }                               
              }
        }
    }
1

There are 1 answers

5
Jeremy Thompson On

Is not supported on this platform error typically means you tried to load an x64 assembly in a x86 process or vice versa.

Microsoft.Data.SqlClient contains architecture specific files.

Double check your Nuget Package is for the correct architecture your machine supports.