/// <summary> /// Opens a specified connection object. /// </summary> /// <param name="connection">Connection to open.</param> /// <remarks> /// Use this method to open a connection returned by the <see cref="GetConnection"/> method. /// <para/>This method displays a login dialog if your connection has the <see cref="LoginPrompt"/> /// property set to <b>true</b>. Once you have entered an user name and password in /// this dialog, it will remeber the entered values and will not used anymore in this report session. /// </remarks> protected void OpenConnection(DbConnection connection) { if (!String.IsNullOrEmpty(FLastConnectionString)) { // connection string is already provided, use it and skip other logic. connection.ConnectionString = FLastConnectionString; } else { // try the global DatabaseLogin event string oldConnectionString = ConnectionString; DatabaseLoginEventArgs e = new DatabaseLoginEventArgs(ConnectionString); Config.ReportSettings.OnDatabaseLogin(this, e); // that event may do the following: // - modify the ConnectionString // - modify the username/password // - there is no event handler attached to the event, so it does nothing. if (oldConnectionString != e.ConnectionString) { // the connection string was modified. Set the FLastConnectionString to use it next time silently. FLastConnectionString = e.ConnectionString; } else { if (!String.IsNullOrEmpty(e.UserName) || !String.IsNullOrEmpty(e.Password)) { // the username/password was modified. Get new connection string FLastConnectionString = GetConnectionStringWithLoginInfo(e.UserName, e.Password); } else if (LoginPrompt) { if (String.IsNullOrEmpty(FLastConnectionString)) { using (AskLoginPasswordForm form = new AskLoginPasswordForm()) { if (form.ShowDialog() == DialogResult.OK) { FLastConnectionString = GetConnectionStringWithLoginInfo(form.Login, form.Password); } } } } } // update the connection if it's not done yet if (!String.IsNullOrEmpty(FLastConnectionString)) { connection.ConnectionString = FLastConnectionString; } } connection.Open(); Config.ReportSettings.OnAfterDatabaseLogin(this, new AfterDatabaseLoginEventArgs(connection)); }
/// <summary> /// Opens a specified connection object. /// </summary> /// <param name="connection">Connection to open.</param> /// <remarks> /// Use this method to open a connection returned by the <see cref="GetConnection"/> method. /// <para/>This method displays a login dialog if your connection has the <see cref="LoginPrompt"/> /// property set to <b>true</b>. Once you have entered an user name and password in /// this dialog, it will remeber the entered values and will not used anymore in this report session. /// </remarks> public void OpenConnection(DbConnection connection) { if (connection.State == ConnectionState.Open) { return; } if (!String.IsNullOrEmpty(lastConnectionString)) { // connection string is already provided, use it and skip other logic. connection.ConnectionString = lastConnectionString; } else { // try the global DatabaseLogin event string oldConnectionString = ConnectionString; DatabaseLoginEventArgs e = new DatabaseLoginEventArgs(ConnectionString); Config.ReportSettings.OnDatabaseLogin(this, e); // that event may do the following: // - modify the ConnectionString // - modify the username/password // - there is no event handler attached to the event, so it does nothing. if (oldConnectionString != e.ConnectionString) { // the connection string was modified. Set the FLastConnectionString to use it next time silently. lastConnectionString = e.ConnectionString; } else { if (!String.IsNullOrEmpty(e.UserName) || !String.IsNullOrEmpty(e.Password)) { // the username/password was modified. Get new connection string lastConnectionString = GetConnectionStringWithLoginInfo(e.UserName, e.Password); } else if (LoginPrompt) { ShowLoginForm(lastConnectionString); } } // update the connection if it's not done yet if (!String.IsNullOrEmpty(lastConnectionString)) { connection.ConnectionString = lastConnectionString; } } connection.Open(); Config.ReportSettings.OnAfterDatabaseLogin(this, new AfterDatabaseLoginEventArgs(connection)); }