question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: Expose a connection string parsing API

See original GitHub issue

Is your feature request related to a problem? Please describe. I want to log the endpoint Uri (but not the key of course), but all I have is a connection string

Describe the solution you’d like var (uri,key) = CosmosClient.ParseConnectionString(connectionString)

Describe alternatives you’ve considered https://stackoverflow.com/a/66746588/11635

Additional context I’ve previously arrived at this (not my original work), and wan’t to do better than that without replicating the logic @NoahStahl found.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bartelinkcommented, Mar 23, 2021

@ealsur I know I can (and thanks for trying to help) - I actually have, for now. I happen even to be able to squirrel it away in a wrapper lib without too much junk leaking into normal apps.

My point, and the reason for this issue, is that the SDK should provide an affordance that lets me naturally emit the Endpoint Uri for diagnostic purposes before I [fail to] ConnectAndInitializeAsync. For the normal lazy-initialized path, a credible solution exists: use CosmosClient.Endpoint - me re-implementing clones of internal behavior of the SDK is not a good solution overall though. I’m raising this issue in the hope e.g. that the V4 SDK provides a better overall answer.

While I’m overstepping the mark, I’m wondering whether overloading of constructors and CreateAndInitializeAsync by a) Connection String b) Endpoint and Key is sustainable and/or will become hard to maintain/add new mechanisms to over time.

0reactions
ealsurcommented, Mar 23, 2021

@bartelink you can use System.Data.Common.DbConnectionStringBuilder

DbConnectionStringBuilder builder = new DbConnectionStringBuilder
            {
                ConnectionString = connectionString
            };

            if (builder.TryGetValue("AccountKey", out object key))
            {
                AuthKey = key.ToString();
            }

            if (builder.TryGetValue("AccountEndpoint", out object uri))
            {
                ServiceEndpoint = new Uri(uri.ToString());
            }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Expose connection string parsing functions #1524 - jackc/pgx
I'm working on an internal package for managing multiple connection strings and connection pools. As part of this, I need to parse connection ......
Read more >
Is there any connection string parser in C#? - ...
I have a connection string and I want to be able to peek out for example "Data Source". Is there a parser, or...
Read more >
3.3 Connecting to Oracle Database
Connection String Attributes · Connection String Builder · Specifying the Data Source Attribute · Using Transport Layer Security and Secure Sockets Layer.
Read more >
DbConnectionStringBuilder.ConnectionString Property
The ConnectionString property of the DbConnectionStringBuilder class acts generally as a mechanism for creating and parsing semicolon-delimited lists of key/ ...
Read more >
Parsing a Connection String With Sprache
Sprache is a very cool lightweight parser library for C#. Today I was experimenting with parsing EasyNetQ connection strings, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found