Some checks are pending
CI / Build og unit tests (push) Waiting to run
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
- .NET 10 solution with Core, Connectivity, Rules, Contracts, Agent, Web and Hub - Capability model gating collectors and rules by SQL Server version (2000 and later); rules that cannot run are reported as not measurable, never as passed - Connectivity via Microsoft.Data.SqlClient with ODBC fallback for legacy instances, hardened monitoring session settings valid back to SQL Server 2000 - Support lifecycle rule (SQLI-VER-001) with lifecycle data shipped as a rule pack - Version-aware least-privilege permissions script, verified by integration tests against SQL Server in Docker (reads monitoring sources, cannot read customer data) - Forgejo Actions CI, contributing guide, code of conduct, issue templates, legacy version notes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using System.Data.Odbc;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace SQLInsight.Connectivity;
|
|
|
|
internal static class ConnectionStrings
|
|
{
|
|
public const string ApplicationName = "SQLInsight Pro";
|
|
|
|
public static string ForSqlClient(ConnectionTarget target)
|
|
{
|
|
var builder = new SqlConnectionStringBuilder
|
|
{
|
|
DataSource = target.Server,
|
|
InitialCatalog = "master",
|
|
ApplicationName = ApplicationName,
|
|
ConnectTimeout = (int)target.ConnectTimeout.TotalSeconds,
|
|
Encrypt = target.Encryption == EncryptionMode.Mandatory ? SqlConnectionEncryptOption.Mandatory : SqlConnectionEncryptOption.Optional,
|
|
TrustServerCertificate = target.TrustServerCertificate,
|
|
// Monitoring must never hold a pooled session with leftover state on a busy server.
|
|
Pooling = false,
|
|
};
|
|
|
|
if (target.Authentication == AuthenticationMode.Windows)
|
|
{
|
|
builder.IntegratedSecurity = true;
|
|
}
|
|
else
|
|
{
|
|
builder.UserID = RequireUserName(target);
|
|
builder.Password = target.Password ?? string.Empty;
|
|
}
|
|
|
|
return builder.ConnectionString;
|
|
}
|
|
|
|
public static string ForOdbc(ConnectionTarget target)
|
|
{
|
|
var builder = new OdbcConnectionStringBuilder
|
|
{
|
|
Driver = target.OdbcDriver,
|
|
};
|
|
builder["Server"] = target.Server;
|
|
builder["Database"] = "master";
|
|
builder["APP"] = ApplicationName;
|
|
builder["Encrypt"] = target.Encryption == EncryptionMode.Mandatory ? "yes" : "no";
|
|
builder["TrustServerCertificate"] = target.TrustServerCertificate ? "yes" : "no";
|
|
|
|
if (target.Authentication == AuthenticationMode.Windows)
|
|
{
|
|
builder["Trusted_Connection"] = "yes";
|
|
}
|
|
else
|
|
{
|
|
builder["UID"] = RequireUserName(target);
|
|
builder["PWD"] = target.Password ?? string.Empty;
|
|
}
|
|
|
|
return builder.ConnectionString;
|
|
}
|
|
|
|
private static string RequireUserName(ConnectionTarget target) =>
|
|
string.IsNullOrWhiteSpace(target.UserName)
|
|
? throw new ArgumentException($"A user name is required for SQL login authentication to '{target.Server}'.", nameof(target))
|
|
: target.UserName;
|
|
}
|