简体   繁体   中英

what is the best way to create connection Class in C#

I have windows form that asking user name, password and databaseName, and the way I am using to connect database open to SQL injection!. I want to create different class for my connection string, also want to use get and set methods if it is necessary. what is the best way to do that?

Thanks?

my Connection String

  string db1 = "Data Source=" + txtDatabase.Text + ";User Id=" + txtUserID.Text.ToUpper() + ";Password=" + txtUserPassword.Text + ";";

connection builder

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM