2
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();
    }
}

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

4

1 回答 1

5

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

当设置为 false 或 no(强烈推荐)时,如果连接打开或曾经处于打开状态,则不会将密码等安全敏感信息作为连接的一部分返回。重置连接字符串会重置所有连接字符串值,包括密码。公认的值是truefalseyesno

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

于 2013-01-07T07:32:02.603 回答