using System.Data.SqlClient;
namespace ConnectToDB
{
class Program
{
static void Main(string[] args)
{
// 数据库连接字符串
string connString = "Data Source=<ip/hostname>;Initial Catalog=<db_name>;User ID=<username>;Password=<password>";
// 创建连接
using (SqlConnection connection = new SqlConnection(connString))
{
// 打开连接
connection.Open();
// 处理请求
// ...
// 关闭连接
connection.Close();
}
}
}
}