Given a Event Hub Name, how can I get connection string in C#? I googled a bit, but nothing useful found so far. Thanks
How to Get Azure Event Hub Connection String in C#?
1.3k Views Asked by justyy At
2
There are 2 best solutions below
0

Not sure if this is what you mean, but if you want to access an Event Hub through C# you need to provide the EH connection string into your code. This can be retrieved by adding a Shared access policy for the Event hub that you are trying to access.
Edit: If you are trying to actually create the connection string yourself you could follow this sample where you create the SAS-token yourself. But you would still need to provide the Primary key that is set on the policy from Azure.
Using AAD authentication for an EventHub
Full example and docs
Acquiring the Connection Strings of configured Access Policies
You can use these two Nuget packages:
Then you can use the resource group name and the eventhub name to retrieve the connection string. You will need to iterate the subscriptions and resource groups if you don't have this information.