EDIT: I understand the migration from 100 to 101 for newer .NET projects. What I am failing to understand is how the 102 namespace communicates with SQL Server. This question comes to mind considering that Microsoft has now deprecated one of its clients, the SQL Native Client (SNAC).

i.e. *.Data.SqlClient命名空间如何与SQL Server 2022数据库通信?随着SQL Native Client弃用的宣布,开发人员是否需要担心他们的代码库?


通过使用C#编写代码并使用Microsoft SQL Server后端,我们目前正在将数据库从SQL Server 2019迁移到较新的SQL Server 2022环境.我们的代码库显式使用System.Data.SqlClient或更新的Microsoft.Data.SqlClient命名空间中的SqlConnection个对象.

根据微软的网站,这SQL Server Native Client (SNAC) is now deprecated in SQL Server 2022人.我们的代码库是否需要从使用System.Data.SqlClient.SqlConnection个对象(或Microsoft.Data.SqlClient.SqlConnection个)迁移,以便继续使用较新的SQL Server 2022(+)实例?

示例连接字符串:

<add name="myConnection" 
     connectionString="Server=DEV-SQLSERVER2019-01.mycompany.local,1433;TrustServerCertificate=True;Database=Tokens;User ID=TokensApp;Password=ABC123"  
     providerName="Microsoft.Data.SqlClient"/>

示例代码:

//using System.Data.SqlClient;
using Microsoft.Data.SqlClient;

private static string CreateToken(string code, string email)
{
    string token;

    try 
    {
        using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString)) 
        {
            sqlConn.Open();

            using (SqlCommand sqlCmd = new SqlCommand()) 
            {
                sqlCmd.Connection = sqlConn;
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.CommandText = "spCreateToken";
                sqlCmd.Parameters.Add("@Token", SqlDbType.UniqueIdentifier).Value = NEW_GLOBAL_TOKEN();
                sqlCmd.Parameters.Add("@Code", SqlDbType.NVarChar, 6).Value = code.ToUpper();
                sqlCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 80).Value = email.ToLower();

                token = sqlCmd.ExecuteScalar().ToString();
            }
        }
    }
    catch (SqlException exSQL) when (exSQL.Message.Contains("Violation of UNIQUE KEY constraint")) 
    {
        throw new Exception(String.Format("This email address '{0}' has already been sent an invitiation.", email));
    }
    catch (Exception ex) when (ex.Message.Equals("Object reference not set to an instance of an object.")) 
    {
        throw new InvalidOperationException(String.Format("The email address provided '{0}' has already signed-up.", email));
    }

    return token;
}

如果此代码库确实需要更改-我应该如何在我的C#代码库中与Microsoft SQL Server 2022+数据库对接:

  • 连接字符串格式
  • 数据库连接类类型
  • 数据库命令类类型
  • 个人数据库对象类型(S)
  • 单个数据库异常类类型
  • 数据库交易类类型(S)
  • SQL Server数据库用户定义值/表值参数类型

我已经读到了新的SQL Server 2022的弃用更改,但我不清楚这是否或如何实际影响我们的代码库,该代码库使用C#并显式调用SqlConnection类来连接到我们的Microsoft SQL Server数据库.看起来,如果需要的话,迁移路径将很麻烦,以确保使用新的SQL客户端对象类型实现正确的功能.

推荐答案

SQL Server Native Client与C#中的SqlClient没有任何关系.它是一个ODBC驱动程序,由C/C++和其他使用ODBC的工具使用.

这只是粉笔和cheese ,苹果和橙子,一个不确定的结论.它与对话完全、完全、完全和绝对无关,它与它无关,它在另一个世界.在C#中,忘记你听说过Native Client,它不适合你.

你只需要担心Microsoft.Data.SqlClient或更老但仍然支持System.Data.SqlClient的版本.

Csharp相关问答推荐

使用GeneratedComInterfaceProperty的.NET 8 COM类对于VB 6/SYS或ALEViewer不可见

自定义JsonEditor,用于将SON序列化为抽象类

使用其可能实现的基类和接口的属性的方法

如何使用Unity和MRTK3将手网添加到Hololens 2应用程序中

==和Tuple对象的相等<>

为什么无法将对象转换为泛型类型

UWP应用程序try 将打包的本机.exe文件加载为C#程序集

C#DateTime.ParseExact不使用特定日期

NET8 Maui&;iOS:AppCenter崩溃错误

如何防止Visual Studio断点以红色突出显示到整行?

使用System.Text.Json进行序列化时发生StackOverflow异常

无法使用[FromForm]发送带有图像和JSON的多部分请求

数据库.Migrate在对接容器重启时失败

Azure Functions v4中的Serilog控制台主题

为什么我在使用有效令牌的情况下仍未获授权?

如何设置WinForms按钮焦点,使其看起来像是被Tab键插入其中?

DropDownListFor未显示选定值

ASP.NET核心8:app.UseStaticFiles()管道执行顺序

在ObservableCollection上使用[NotifyPropertyChangedFor()]源代码生成器不会更新UI

使用免费的DotNet库从Azure函数向Azure文件共享上的现有Excel文件追加行