sql-server - mssql特殊字符编码问题

标签 sql-server azure azure-sql-database node-mssql

我们正在使用 node-mssql 包插入和读取我们的 azure mssql 数据库。 数据库非常简单,因为它只是用作键/值缓存,其中值可以很长并且还包含特殊字符。

数据库架构:

create table cache
(
    id       int identity
        constraint cache_pk
            primary key nonclustered,
    cacheKey varchar(500),
    ttl      bigint,
    value    varchar(max)
)
go

create index cache_cacheKey_index
    on cache (cacheKey desc)
go

create index cache_ttl_index
    on cache (ttl)
go

由于某种原因,当我将值插入“value”时,一些特殊字符没有得到很好的处理。

Dash – example

变成:

Dash  example

我看到法语撇号也发生了同样的事情。 我也尝试过更改排序规则,但这没有帮助。 还尝试使用 nvarchar(max) 作为列类型。

这是插入代码(包括sql):

  const result = await conn.request()
                      .input('key', mssql.VarChar, key)
                      .input('value', mssql.Text, value)
                      .input('ttl', mssql.BigInt, cacheEndTime)
                      .query`INSERT INTO cache (cacheKey, value, ttl) VALUES (@key, @value, @ttl)`;

您能帮忙提供正确的表结构或 sql 语句来完成这项工作吗?

最佳答案

您的问题的答案在以下项目之一中:

  • 服务器排序规则
  • 表格排序规则
  • 字段整理
  • 转换插入文本

例如,如果您创建 nvarchar(如果您有国际场景,我建议您)字段,请将文本插入转换为 N'要插入的文本'。

它会起作用;)

关于sql-server - mssql特殊字符编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66045099/

相关文章:

c# - SqlCommand.ExecuteReader 使用带输出参数的存储过程不返回任何行

c# - 在 Azure 辅助角色中使用 Lucene.NET 引发未处理的异常

sql-server - 无法对数据库执行操作,因为它涉及数据库镜像 session 或可用性组 (Azure)

VSTO 加载项和 SQL 的 Azure 防火墙设置

c# - 如何使用 Fluent NHibernate 和 SchemaUpdate.Execute() 索引外键?

sql-server - 我真的需要使用 "SET XACT_ABORT ON"吗?

c++ - 如何在 C++ 中访问 SQL DB?

azure - 从 GitLab 的 Azure 网站进行部署

c# - 如何不丢失聊天机器人 v4 的对话流?

azure - EF 与 Azure - 处理事务的推荐方法是什么?