SQL_Server_Connection
SQL_Server_Connection
3. Configure Connection
• In the 'Add Connection' window:
- Select 'Microsoft SQL Server (SqlClient)' as the data source.
- Enter the 'Server Name' (e.g., .\SQLEXPRESS for local SQL Server Express).
- Choose 'Windows Authentication' or enter SQL 'username/password'.
- Select the database you want to connect to from the dropdown.
using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
string connectionString = "Server=YOUR_SERVER_NAME;
Database=YOUR_DATABASE_NAME; Integrated Security=True;";
using (SqlConnection con = new SqlConnection(connectionString))
{
try
{
con.Open();
Console.WriteLine("Connection Successful!");
}
catch (Exception ex)
{
Console.WriteLine("Connection Failed: " + ex.Message);
}
}
}
}