简体   繁体   English

在C#中创建连接类的最佳方法是什么

[英]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!. 我有Windows窗体,询问用户名,密码和databaseName,以及我用来将数据库连接到SQL注入的方式! I want to create different class for my connection string, also want to use get and set methods if it is necessary. 我想为我的连接字符串创建不同的类,如果需要,还想使用get和set方法。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C#中实现此类的最佳方法是什么 - What is the best way to implement this class in C# 在 C# 项目中添加 class 库的最佳方法是什么? - What is the best way to add class library in C# project? 在容器 class 内处理 C# 事件的最佳方法是什么? - What is the best way to handle C# events inside a container class? C#确定继承接口类的最佳方法是什么? - C# What is the best way to determine the type of an inherited interface class? 在C#中使用导航类的最佳方法是什么 - What is the best way of using a navigation class in C# 在C#2.0中创建向导的最佳方法是什么? - What is the best way to create a wizard in C# 2.0? C#创建被多个类使用的枚举的最佳方法是什么? - C# What is the best way to create an enum that is used by multiple classes? 在C#中创建简单的全局事件系统的最佳方法是什么? - What is the best way to create a simple global event system in C#? 在C#中创建不可变类的最简洁方法是什么? - What's the most concise way to create an immutable class in C#? 在 C# 中不访问互联网的情况下检查互联网连接的最佳方法是什么? - What is the best way to check internet connection WITHOUT accessing the internet in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM