我有windows表单,询问用户名,密码和databaseName,以及我用来连接数据库打开SQL注入的方式! 我想为我的连接字符串创建不同的类,如果有必要,也想使用get和set方法。最好的方法是什么?
感谢?
我的连接字符串
string db1 = "Data Source=" + txtDatabase.Text + ";User Id=" + txtUserID.Text.ToUpper() + ";Password=" + txtUserPassword.Text + ";";
答案 0 :(得分:1)
连接构建器
System.Data.SqlClient.SqlConnectionStringBuilder builder =
new System.Data.SqlClient.SqlConnectionStringBuilder();
builder["Data Source"] = "(local)";
builder["integrated Security"] = true;
builder["Initial Catalog"] = "AdventureWorks;NewValue=Bad";
Console.WriteLine(builder.ConnectionString);