How do I use System.Data in a .NET Core RC2 console app (Linux, Debian 8)?

我是研究僧i 提交于 2019-12-04 05:21:07
Thomas

Like poke already annotated in the comment is correct. Specify a version to System.Data.SqlClient makes your restore happy ;)

Why is that? System.Data.SqlClient exists in the http://nuget.org gallery. Not specifying a version ("") is not allowed outside of the boundaries of a project (like a nuget feed package) and specifying solely an star "*" (you should never do that, it allows breaking changes) restore the highest available version. Since there is no stable, star will not find anything (there is some magic with the dashes behind). The RC2 version of that library is the mentioned 4.1.0-rc2-24027 and when you ask with 4.1.0-rc2-* it will take the highest of the RC2 builds (but there is only one). In comparison System.Data.Common has a public release on nuget.org for the Universal Windows Platform and is found for that reason.

The RC3 is the next release and only available on developer feeds from the .NET Core and ASP.NET Core team and not the public nuget feed. You should not play with them.

if you are in project.json file, the intellisense guide you now if you have updated the Visual studio with the latest tooling avaiable..

I added the following in the dependencies element and it works perfectly..

"System.Data.SqlClient": "4.1.0-rc2-24027",

On my MINT 19 Tara I do not use System.Data.SqlClient but the newer version Microsoft.Data.SqlClient. Check nuget

After typing the .NET-cli command, the package was downloaded and the reference was added to the project csproj file.

In the code, use the newer namespace:

using Microsoft.Data.SqlClient;

The "regular" code works fine:

 public static void CreateCommand(string queryString, string connectionString)
    {
        using (SqlConnection connection = new SqlConnection(
                   connectionString))
        {
            SqlCommand command = new SqlCommand(queryString, connection);
            command.Connection.Open();
            SqlDataReader reader = command.ExecuteReader() ;
            while( reader.Read() ) {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                   Console.WriteLine( "Column name={0}, Value={1}", 
                        reader.GetName(i),
                        reader.GetValue(i) ); 
                }
            }
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!