To connect to a SQL Server database in C#, you need to use the SqlConnection class, which is provided by the System.Data.SqlClient namespace.
you first define the connection string, which contains information about the SQL Server instance, the database you want to connect to, and the credentials you want to use. You then create a new SqlConnection object using the connection string, and open the connection using the Open() method. Finally, you can perform various database operations, and then close the connection using the Close() method.