【问题标题】:Password escapes in SQL Azure connection stringSQL Azure 连接字符串中的密码转义
【发布时间】:2020-12-23 09:39:28
【问题描述】:

我有一个绝妙的主意,即使用 KeePass 密码管理器生成安全密码并将其提供给我的 DBA。

现在我按如下方式构造了我的 Azure SQL 连接字符串

Server=tcp:something.database.windows.net,1433;Initial Catalog=SomeDbName;Persist Security Info=False;User ID=someuser;Password=[read later];MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

密码包含至少以下字符,以及大写/小写/数字

/"|&@]<#

错误是:ArgumentException: Format of the initialization string does not conform to specification starting at index 151.

在索引 151 处,我可以看到用户名后面的分号(我在编辑示例中将其命名为 someuser,但仅包含小写字母和数字)。 ;Password= 序列之前的 VS 代码点第 151 列

问题:

  • 我的 SQL Azure 密码是否包含非法字符?
  • 哪些需要转义?
  • 如何逃脱它们?

[编辑]:关于双引号的注释,在 C# 字符串中必须始终进行转义。我将连接字符串埋在 Azure App 配置选项卡下。这意味着双引号不太可能被重新转义。我相信 EF Core 目前正确读取 double-quote

【问题讨论】:

  • 我已经通过在没有double-quote 的情况下重新生成密码解决了这个问题,但我仍然对未来的转义感到好奇

标签: entity-framework-core passwords ado.net azure-sql-database connection-string


【解决方案1】:

这里其实指定了转义:connection-strings

简单测试表明,对于你的密码,加单引号就够了:

var csBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();
csBuilder.Password = "/\"|&@]<#";

var cs = csBuilder.ConnectionString;
Console.WriteLine(cs);
Password='/"|&@]<#'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多