Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we remove the dependency to Microsoft.Data.SqlClient in Arcus.Observability.Telemetry.Sql #488

Closed
fgheysels opened this issue Nov 17, 2022 · 0 comments · Fixed by #490
Assignees
Labels
dependencies All issues related to dependencies
Milestone

Comments

@fgheysels
Copy link
Member

fgheysels commented Nov 17, 2022

The Arcus Observability.Telemetry.Sql project now has a dependency on the Microsoft.Data.SqlClient package.
We use this package now just so that we can use the SqlConnectionStringBuilder class. One of the LogSqlDependency methods takes a parameter that accepts a connection-string to a Sql database. We use the SqlConnectionStringBuilder to parse this connection-string and retrieve the servername and the database-name from the connection-string.

I think it is kind of bloated and unnecessary to have a dependency on this package just for this. Since a connection-string is nothing more then a string with multiple key/value pairs, I wonder if we cannot just write a simple 'parser' ourselves that retrieves the parts that we need.

I'm thinking of something really simple like this:

var connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";

var parts = connectionString.Split(';')
			.Select(part => part.Split('='))
			.Where(part => part.Length == 2)
			.Select(kv => new KeyValuePair<string,string>(kv[0],kv[1])).ToArray();

There are of course some edge cases, as a connection string can have a Server component, but it is also possible to have a Data Source component instead.

See also the comments in this PR: #485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies All issues related to dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants