I've got the design habit to have a SqlConnection object populated by a child form, showing the child form, establishing the SqlConnection object and having the populated object passed back to the parent form where execution continues. .NET 2.0 and up 0 as follows:
Parent form:
public SqlConnection sqlcon; //should be property but made it public for this example
public MainForm_Load(object sender, EventArgs e)
{
Login frm = new Login(this);
frm.ShowDialog();
if (this.sqlcon == null)
{ //no login
this.Close();
}
//else, continue execution
}
Login Form:
Mainform parent;
public Login(RandomParade frm)
{
InitializeComponent();
parent = frm;
}
private void btnOK_Click(object sender, EventArgs e)
{
//code to capture login details from textboxes
//test connection
parent.sqlcon = new SqlConnection("connection string with login details here");
this.Close();
}
As this is compiled into a single executable (dll access modifiers treated separate etc...), is having the sqlConnection object public a security risk? Could someone pick up the information at runtime? What would be a better implementation of passing login information to a 'Main' form?