gpt4 book ai didi

c# - ConnectionString 中的可变密码

转载 作者:太空宇宙 更新时间:2023-11-03 17:51:04 27 4
gpt4 key购买 nike

我创建了连接字符串:

connection.ConnectionString = @"Provider=abcdef; Server=123....; Database=abc; User Id=user; Password=xyz"; 

效果很好。我想用变量交换密码:

connection.ConnectionString = @"Provider=abcdef; Server=123....; Database=abc; User Id=user; Password="+textBox1.Text;

我的程序显示错误:

Login failed for user: user... (textBox.Text = "xyz")

你知道如何正确地与变量交换密码吗?

最佳答案

使用SqlConnectionStringBuilder类。

static void Main()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
builder.Password = "YourNewPassword";
string newConnectionString = builder.ConnectionString;
}

关于c# - ConnectionString 中的可变密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524609/

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