Connect string parameters

CreateConnectionString() returns the server to which you are connecting, and it can return additional parameters. In the QvEventLogConnectorElaborate example, UserId and Password are also sent as parameters to the connect string:

public override string CreateConnectionString() { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "CreateConnectionString()"); var login = CreateLoginWindowHelper(); login.ShowDialog(); string connectionString = null; if (login.DialogResult.Equals(true)) { connectionString = String.Format("Server={0};UserId={1};Password={2}", login.GetServer(), login.GetUsername(), login.GetPassword()); } return connectionString; }

The UserId and Password parameters can be used with QvEventLogConnection.cs, where the VerifyCredentials() method is called as a safeguard before the implementation lets the invoking class access any data. In the code example, a parameter is parsed from the connect string for use within the VerifyCredentials() method.

private void VerifyCredentials() { string username, password; this.MParameters.TryGetValue("UserId", out username); this.MParameters.TryGetValue("Password", out password); if (username != "InterBlag" || password != "BlagBlag") { throw new AuthenticationException("Username and/or passowrd is incorrect"); } }
Note: This example is in no way a guaranteed secure way to deal with user credentials and should only be regarded as a showcase of how to work with the parameters in the connect string.

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?