Created a "login" dialog form to grab the server name from the user. Now a valid connection must be made before the Main form loads.

This commit is contained in:
2017-04-12 20:01:32 -05:00
parent 2e19bba711
commit a67dd966bd
9 changed files with 317 additions and 10 deletions
@@ -0,0 +1,37 @@
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;
}
}
}
}