Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Azure by (45.3k points)
recategorized by

I ran this in debug mode, and I attach an image with the details of the exception. How can I know what went wrong? I was trying to insert data in a table. Can't azure give me more details?

Obs: The storage is on Windows Azure not on my machine. The tables were created, but I get this error when inserting data

enter image description here

// Retrieve the storage account from the connection string.

Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***");

// Create the table client.

CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

// Create the table if it doesn't exist.

CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory");

table.CreateIfNotExists();

and this is the insert code:

public static void SetStatus(Employee e, bool value)

{

    try

    {

        // Retrieve the storage account from the connection string.

        Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=###;AccountKey=###");

        // Create the table client.

        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "people" table.

        CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory");

        // Create a new customer entity.

        if (value == true)

        {

            EmployeeOnlineHistory empHistory = new EmployeeOnlineHistory(e.Id);

            empHistory.IsOnline = true;

            empHistory.OnlineTimestamp = DateTime.Now;

            TableOperation insertOperation = TableOperation.Insert(empHistory);

            table.Execute(insertOperation);

        }

        else

        {

            TableQuery<EmployeeOnlineHistory> query = new TableQuery<EmployeeOnlineHistory>()

                .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, e.Id.ToString()));

            EmployeeOnlineHistory entity = table.ExecuteQuery(query).Take(1).FirstOrDefault();

            if ((entity!=null)&&(entity.IsOnline))

            {

                entity.IsOnline = false;

                entity.OfflineTimestamp = DateTime.Now;

                entity.OnlineTime = (entity.OfflineTimestamp - entity.OnlineTimestamp);

                TableOperation updateOperation = TableOperation.Replace(entity);

                table.Execute(updateOperation);

            }

            else

            {

                EmployeeOnlineHistory empHistory = new EmployeeOnlineHistory(e.Id);

                empHistory.IsOnline = false;

                empHistory.OfflineTimestamp = DateTime.Now;

                TableOperation insertOperation = TableOperation.Insert(empHistory);

                table.Execute(insertOperation);

            }

        }

    }

    catch (Exception ex)

    {

        //var details = new System.IO.StreamReader(((Microsoft.WindowsAzure.Storage.StorageException)ex)..Response.GetResponseStream()).ReadToEnd();

        LogFile.Error("EmployeeOnlineHistory.setStatus",ex);

    }

}

1 Answer

+2 votes
by (16.8k points)
edited by

This issue may contain a forward slash in your RowKey.

While performing it, most of the time you will receive this error - 'OutOfRangeInput - One of the request inputs is out of range' while trying to add manually through the storage emulator.

Looking for Azure material from basics! Refer to this video on Azure provided by Intellipaat:

Please try to run this extension method in order to handle this:

public static string ToAzureKeyString(this string str)

{

    var sb = new StringBuilder();

    foreach (var c in str

        .Where(c => c != '/'

                    && c != '\\'

                    && c != '#'

                    && c != '/'

                    && c != '?'

                    && !char.IsControl(c)))

        sb.Append(c);

    return sb.ToString();

}

It worked for me, hope it helps!

Browse Categories

...