38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
|
using System.Data.SqlClient;
|
|
using System.Windows.Forms;
|
|
using AdvertsingProfitControl.Properties;
|
|
|
|
namespace AdvertsingProfitControl
|
|
{
|
|
public partial class FrmDatabaseSelector : Form
|
|
{
|
|
public bool _connectionSuccessful = false;
|
|
|
|
public FrmDatabaseSelector()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
var connectionString = "Data Source=" + serverNameTextBox.Text + ";" + "Initial Catalog=AdvertisingProfitControl;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework";
|
|
try
|
|
{
|
|
//Test the connection string with a forced timeout of 2 seconds.
|
|
using (var conn = new SqlConnection(connectionString + "Connection Timeout=2"))
|
|
{
|
|
conn.Open(); // throws if invalid
|
|
}
|
|
Settings.Default.ConnectionString = connectionString;
|
|
_connectionSuccessful = true;
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
label1.Text = ex.Message;
|
|
}
|
|
}
|
|
}
|
|
}
|