mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace SqlServerSample
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
// Build connection string
|
|
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
|
|
builder.DataSource = "localhost"; // update me
|
|
builder.UserID = "sa"; // update me
|
|
builder.Password = "your_password"; // update me
|
|
builder.InitialCatalog = "master";
|
|
|
|
// Connect to SQL
|
|
Console.Write("Connecting to SQL Server ... ");
|
|
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
|
|
{
|
|
connection.Open();
|
|
Console.WriteLine("Done.");
|
|
}
|
|
}
|
|
catch (SqlException e)
|
|
{
|
|
Console.WriteLine(e.ToString());
|
|
}
|
|
|
|
Console.WriteLine("All done. Press any key to finish...");
|
|
Console.ReadKey(true);
|
|
}
|
|
}
|
|
} |