Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.46k stars 4.8k forks source link

[BUG] Keep consistency between different database endpoint connection strings #45779

Closed erdembayar closed 1 month ago

erdembayar commented 2 months ago

Library name and version

Azure.Data.Tables 12.8.3

Describe the bug

Connection string for Blob storage and Table storage is not consistent, making it hard to notice that we're working with table storage. I wish Azure SDK could use a more explicit connection string to prevent errors. For example:

  1. Here we use the explicit BlobEndpoint= prefix. "BlobConnectionString": "BlobEndpoint=https://myvalid.blob.core.windows.net", 2. However, for table storage, if I use TableEndPoint= it throws an exception. "TableConnectionString": "https://myvalid.table.core.windows.net", You can see this usage example from https://stackoverflow.com/a/69796751 too.

Expected behavior

Below code don't throw exception

public static async Task createTable(string accountName, string tableName)
{
            string tableEndpoint = string.Format("TableEndPoint=https://{0}.table.core.windows.net/",accountName);
            var token = await new AzureServiceTokenProvider().GetAccessTokenAsync("https://storage.azure.com/");
            var tokenCredential = new TokenCredential(token);
            var storageCredentials = new StorageCredentials(tokenCredential);
            var tableClient = new CloudTableClient(new Uri(tableEndpoint), storageCredentials);
            var table = tableClient.GetTableReference(tableName);
            table.CreateIfNotExistsAsync().Wait();
}

Actual behavior

If I use "TableConnectionString": " TableEndPoint=https://myvalid.table.core.windows.net" instead of "TableConnectionString": "https://myvalid.table.core.windows.net" then it throws an exception.

Reproduction Steps

public static async Task createTable(string accountName, string tableName)
{
            string tableEndpoint = string.Format("TableEndPoint=https://{0}.table.core.windows.net/",accountName);
            var token = await new AzureServiceTokenProvider().GetAccessTokenAsync("https://storage.azure.com/");
            var tokenCredential = new TokenCredential(token);
            var storageCredentials = new StorageCredentials(tokenCredential);
            var tableClient = new CloudTableClient(new Uri(tableEndpoint), storageCredentials);
            var table = tableClient.GetTableReference(tableName);
            table.CreateIfNotExistsAsync().Wait();
}

Environment

Azure C# No response

github-actions[bot] commented 2 months ago

@christothes @JonathanCrd

github-actions[bot] commented 2 months ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire commented 2 months ago

Hi @erdembayar. Thanks for reaching out and we regret that you're experiencing difficulties. The Azure SDK clients do not define connection string formats; they support the form exposed by the Azure service. The Azure SDK packages intentionally do not extend or alter connection strings defined by the service. It is intended that connection strings are used for "getting started" scenarios and are copy/pasted directly from the Azure portal. We do not recommend formatting connection strings by hand nor using them for production scenarios.

In this case, the naming and format are controlled by the Azure Storage service. To ensure that the right team has visibility and can help, your best path forward for would be to open an Azure support request or make your suggestion on the Azure Feedback site.

github-actions[bot] commented 2 months ago

Hi @erdembayar. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

erdembayar commented 2 months ago

Thank you, created https://feedback.azure.com/d365community/idea/f6ee7456-3a6a-ef11-a4e6-6045bdb6f632

christothes commented 2 months ago

Hi @erdembayar - Another issue to point out - the Uri you are constructing is not valid.

string accountName = "foo";
string tableEndpoint = string.Format("TableEndPoint=https://{0}.table.core.windows.net/", accountName);
new Uri(tableEndpoint); // throws UriFormatException: Invalid URI: The URI scheme is not valid.

The Uri parameter to TableClient should be a valid Uri like:

string.Format("https://{0}.table.core.windows.net/", accountName);
erdembayar commented 2 months ago

Hi @erdembayar - Another issue to point out - the Uri you are constructing is not valid.

string accountName = "foo";
string tableEndpoint = string.Format("TableEndPoint=https://{0}.table.core.windows.net/", accountName);
new Uri(tableEndpoint); // throws UriFormatException: Invalid URI: The URI scheme is not valid.

The Uri parameter to TableClient should be a valid Uri like:

string.Format("https://{0}.table.core.windows.net/", accountName);

That is the whole point of this issue. The Azure SDK connection is not consistent between blob and table connections. In blob storage, it asks for BlobEndpoint= but not for table connection.

github-actions[bot] commented 1 month ago

Hi @erdembayar, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

erdembayar commented 1 month ago

/unresolve