Skip to main content

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"); } }
Information noteThis 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 page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!