using System;
using System.Data;
using System.Data.SqlClient;
class MainClass
{
static void Main(string[] args)
{
string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;";
SqlConnection conn = new SqlConnection(connString);
try {
conn.Open();
Console.WriteLine("Connection opened.");
}
catch (SqlException e) {
Console.WriteLine("Error: " + e);
}
finally {
conn.Close();
Console.WriteLine("Connection closed.");
}
}
}
|