다음은 작동하는 데 사용됩니다.
public void CreateTableIfMissing()
{
var info = new StorageInfo(); // initialized with tablename and connectionstring
var storageAccount = CloudStorageAccount.Parse(info.ConnectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference(info.TableName);
try
{
table.CreateIfNotExists();
var batchOperation = new TableBatchOperation();
var s = DateTime.Now.ToString();
var entry = new TableEntity("partkey"+s,"rowkey"+s);
batchOperation.Insert(entry);
table.ExecuteBatch(batchOperation);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
오류 정보는
{Microsoft.WindowsAzure.Storage.StorageException:
ErrorCode "InvalidInput"
Element 0 in the batch returned an unexpected response code.
StatusMessage:0:Bad Request - Error in query syntax
이 테이블은 Azure 동기화를 사용하여 Serilog를 통한 오류 로깅에 사용됩니다. Azure Storage Explorer에 연결하면 여전히 로그 레코드를 받고 있음을 알 수 있습니다.
연결 문자열을 변경하지 않았습니다.
[최신 정보]
단일 작업을 시도하고 있지만 문제가 있습니다.
'TableOperation' does not contain a constructor that takes 2 arguments
Cannot access internal constructor 'TableOperation' here
[최신 정보]
Ivan의 조언을 따르지만 ToString ( "o") 매개 변수를 생략하면 오류는 다음과 같습니다.
ErrorMessage:The 'PartitionKey' parameter of value 'partkey3/7/2019 8:33:25 PM' is out of range.
이것은 의미가 있습니다.
왜 그것이 효과가 있었는지 궁금합니다!
최신 정보:
이전 코드의 오류 메시지 (업데이트 코드가 아님) :
{Microsoft.WindowsAzure.Storage.StorageException:
ErrorCode "InvalidInput"
Element 0 in the batch returned an unexpected response code.
StatusMessage:0:Bad Request - Error in query syntax
그 이유는 테이블 스토리지의 partkey 및 rowkey가 "/"와 같은 문자를 허용하지 않기 때문입니다. 그리고 partkey와 rowkey의 접미사로 "/"문자를 포함하는 DateTime.Now.ToString ()을 사용하면 오류가 발생합니다. 날짜 / 시간의 형식을 지정하고 "/"를 제거 DateTime.Now.ToString("o")
하십시오. 코드 (또는 다른 올바른 형식)에서 사용할 수 있습니다 .
업데이트 된 코드의 경우 :
오류는에 TableOperation class
생성자 (매개 변수 또는 매개 변수 없음) 가 없기 때문 입니다. TableOperation 클래스로 이동하여 사용법을 살펴볼 수 있습니다.
당신이 경우에, 당신은 그것의 정적을 사용해야 Insert method
처럼 var op = TableOperation.Insert(entry)
대신 var op = new TableOperation(entry,TableOperationType.Insert)
.
또한 알아야 할 한 가지는 테이블 스토리지의 partkey 및 rowkey는 "/"와 같은 문자를 허용하지 않으므로 datetime.now
partkey 및 rowkey의 접미사에 사용할 때는 var s = DateTime.Now.ToString("o")
. 그렇지 않으면 오류가 발생합니다.
샘플 코드가 잘 작동합니다.
public void CreateTableIfMissing()
{
var info = new StorageInfo(); // initialized with tablename and connectionstring
var storageAccount = CloudStorageAccount.Parse(info.ConnectionString);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference(info.TableName);
try
{
table.CreateIfNotExists();
var s = DateTime.Now.ToString("o");
var entry = new TableEntity("partkey" + s, "rowkey" + s);
var op = TableOperation.Insert(entry);
table.Execute(op);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다