[英]C# Program saving data to Google FirestoreDB fails on some computers (StatusCode=Unavailable; grpc_status: 14)
I have a C# program that reads the computers specs and saves them to a Google FirestoreDB.我有一个 C# 程序,它读取计算机规格并将它们保存到 Google FirestoreDB。 In 95% of the computers, everything works fine.
在 95% 的计算机中,一切正常。 But some computers (can't find a common denominator) come back with the error:
但是有些计算机(找不到共同点)返回错误:
Grpc.Core.RpcException: Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")
grpc_status: 14
The environment variable GOOGLE_APPLICATION_CREDENTIALS has the correct path to the keyfile.json which has this content (Downloaded from google cloud console. Sensitive data removed):环境变量 GOOGLE_APPLICATION_CREDENTIALS 具有指向具有此内容的 keyfile.json 的正确路径(从谷歌云控制台下载。敏感数据已删除):
{ "type": "service_account", "project_id": "project-id",
"private_key_id": "XXXXXXXXXXXX", "private_key": "-----BEGIN PRIVATE
KEY-----XXXXXXXXXXXX---END PRIVATE KEY-----\n", "client_email":
"XXXXXX@XXXXXX.iam.gserviceaccount.com", "client_id": "XXXXXX",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":
"https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url":
"https://www.googleapis.com/robot/v1/metadata/x509/XXXXXX.iam.gserviceaccount.com"
}
Here's the C# code that saves the data to the FirestoreDB:这是将数据保存到 FirestoreDB 的 C# 代码:
try
{
string GoogleCloudProjectId = "project-id";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", AppDomain.CurrentDomain.BaseDirectory + "keyfile.json");
FirestoreDb db = FirestoreDb.Create(GoogleCloudProjectId);
DocumentReference docRef = db.Collection("inventory").Document(systemSpecs.ItemID);
await await docRef.SetAsync(systemSpecs).ContinueWith(q =>
{
if (q.IsCompleted && !q.IsFaulted)
{
MessageBox.Show("Added successfully to inventory.", "Ok", MessageBoxButton.OK, MessageBoxImage.Information);
}
return q;
});
}
catch (Grpc.Core.RpcException rpcEx) {
MessageBox.Show(rpcEx.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
catch (Exception ex)
{
MessageBox.Show(ex.GetType().ToString());
MessageBox.Show("Error:\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", null);
Environment.Exit(0);
}
Using the latest packages versions available from NuGet (Visual Studio):使用 NuGet (Visual Studio) 提供的最新软件包版本:
Google.Api.Gax = v3.2.0
Google Api.Gax.Grpc = v3.2.0
Google Api.Gax.Grpc.GrpcCore = v3.2.0
Google.Cloud.Firestore = v2.3.0
Google.Cloud.Firestore.V1 = v2.2.0
Grpc.Auth = v2.34.0
Grpc.Core = v2.34.0
Grpc.Core.Api = v2.34.0
The computer has internet access (Tested with both wifi and wired connection).电脑可以上网(通过 wifi 和有线连接测试)。 It pings fine google.com, accounts.google.com, oauth2.googleapis.com, www.googleapis.com .
It pings fine google.com, accounts.google.com, oauth2.googleapis.com, www.googleapis.com . I also disabled the Windows Firewall, and this made no difference.
我还禁用了 Windows 防火墙,这没什么区别。 This happens in computers running Windows 7 and Windows 10.
这发生在运行 Windows 7 和 Windows 10 的计算机上。
Using the same internet connection, other computers running the same program everything works fine.使用相同的互联网连接,运行相同程序的其他计算机一切正常。
Why is the GRPC call not working on some computers?为什么 GRPC 调用在某些计算机上不起作用? Not sure what else I can check/try.
不知道我还能检查/尝试什么。 Thanks!
谢谢!
It turned out that the problem was that the timezone was not correct in the computers where that were presenting the problem.事实证明,问题在于出现问题的计算机中的时区不正确。
This would have been much easier to identify if the error message was more descriptive, since the computers did have network connectivity to Google's servers.如果错误消息更具描述性,这将更容易识别,因为计算机确实与 Google 的服务器有网络连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.