namespace SqlConnectionTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnTestConnection_Click(object sender, EventArgs e)
{
// Server= SQL server kurulu olduğu sunucu Database= Veritabanı ismi User ıd= Veritabanı kullanıcı adı Password= Şifresi
string connectionString = "Server=localhost;Database=TestDB;User Id=sa;Password=12345;";
using (SqlConnection conn = new SqlConnection(connectionString))
{
try
{
conn.Open();
MessageBox.Show(" Bağlantı başarılı!", "SQL Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(" Bağlantı hatası:\n" + ex.Message, "SQL Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conn.Close();
}
}
}
}
}