gpt4 book ai didi

.net - 为什么DataContext.Connection.ConnectionString 获取不到密码

转载 作者:行者123 更新时间:2023-12-02 05:18:56 25 4
gpt4 key购买 nike

class Program
{
private const string Sqlconnstr = "Data Source=.;Initial Catalog = LINQtoSQL;UID = Scarface;PWD = kaka1983513!;";

static void Main(string[] args)
{
var dataContext = new DataContext(Sqlconnstr);
var books = dataContext.GetTable<Book>();
var query = from book in books
select book;
var list = query.ToList(); //If i uncomment this line,i can't get the full string without 'PWD = 123456'.
Console.WriteLine(dataContext.Connection.ConnectionString);

Console.ReadLine();
}
}

如何在 query.ToList() 命令后使用 'PWD = 123456' 获取完整字符串。

最佳答案

我不确定为什么您需要重新读取连接信息,但我认为您遇到的问题是 PersistSecurityInfo :

When set to false or no (strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password. Recognized values are true, false, yes, and no.

此连接字符串参数的默认值为 false

关于.net - 为什么DataContext.Connection.ConnectionString 获取不到密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14190836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com