我试图使用.NET core在Google Datastore中存储一些数据。 以下是Visual Studio Code中的Program.cs文件。
using System;
using System.Collections.Generic;
using Google.Cloud.Datastore.V1;
namespace datastoreconsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Lets add some Phones!!");
CreatePhone();
Console.WriteLine("Phones Added!");
}
static void CreatePhone()
{
string ProjectId = "reviews-portal-7751";
string kind = "Phones"; // we are storing phones thats why phones kind
var db = DatastoreDb.Create(ProjectId); //create datastore db
List<Entity> PhoneEntity = new List<Entity>(); //list of phones
for(int i=0;i<5;i++)
{
PhoneEntity.Add(
new Entity
{
Key =db.CreateKeyFactory(kind).CreateKey($"key{i}"),
["PID"] = $"PH{i}",
["Pname"] = $"Phone-{i}",
["Price"] = $"1000{i}",
}
);
}
using(var transaction = db.BeginTransaction())
{
transaction.Upsert(PhoneEntity);
transaction.Commit();
}
}
}
}
该代码没有语法错误。 但是当我运行它时,出现一个未处理的异常错误。
发生异常:CLR / Grpc.Core.RpcException未处理 类型“ Grpc.Core.RpcException”的异常发生在 System.Private.CoreLib.dll:“状态(StatusCode =不可用, Detail =“连接失败”)' System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在Grpc.Core.Internal.AsyncCall
2.UnaryCall(TRequest msg)
2 方法,字符串主机,CallOptions选项,TRequest请求)位于 Grpc.Core.Internal.InterceptingCallInvoker.BlockingUnaryCall [TRequest,TResponse](方法
at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method2 method, String host, CallOptions options, TRequest request) at Google.Cloud.Datastore.V1.Datastore.DatastoreClient.BeginTransaction(BeginTransactionRequest request, CallOptions options) at Google.Api.Gax.Grpc.ApiCall.<>c__DisplayClass0_0
2.b__1(TRequest req,CallSettings cs)位于 Google.Api.Gax.Grpc.ApiCallRetryExtensions。<> c__DisplayClass1_0`2.b__0(TRequest 请求,请致电CallSettings(callSettings)) Google.Cloud.Datastore.V1.DatastoreClientImpl.BeginTransaction(BeginTransactionRequest 请求,请致电CallSettings(callSettings)) Google.Cloud.Datastore.V1.DatastoreDbImpl.BeginTransaction(CallSettings 的datastoreconsole.Program.CreatePhone()中的callSettings) c:\ Users \ abinas.patra \ datastoreconsole \ Program.cs:第36行位于 datastoreconsole.Program.Main(String [] args)在 c:\ Users \ abinas.patra \ datastoreconsole \ Program.cs:第12行
我该如何解决此错误?