Firebase Realtime Database connection killed: Different Region
It looks like the google-services.json
file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created. In such cases the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.
There are two possible solutions:
- Download an updated
google-services.json
from the Firebase console, and add that to your Android app. - Specify the database URL in your code instead, like this:
FirebaseDatabase.getInstance("https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app")...
Both have the same result, so pick whichever one seems easiest to you.
Firebase Database connection was forcefully killed by the server: Different region #flutter
This happens because, when you created your project at that time the Realtime Database was not enabled, that's why the google-services.json
file don't contain the url
to our Realtime Database.
I was also faced with a same problem, here's what I did.
We can also download an updated google-services.json
file. But I manually added the url.
from this:
{
"project_info": {
"project_number": "xxx4071207xxx",
"project_id": "xxxantonixxx",
"storage_bucket": "xxxantonixxx.appspot.com"
},
to this:
{
"project_info": {
"project_number": "xxx4071207xxx",
"firebase_url": " https://multiapp-f0e1e-default-rtdb.europe-west1.firebasedatabase.app",
"project_id": "xxxantonixxx",
"storage_bucket": "xxxantonixxx.appspot.com"
},
You'll get your database Url from here:
But wait... it still might not work.
If you make changes to the google-services.json
file. And recompile the app from start, still the changes DONOT take place immediately.
In my case, even if I deleted the google-services.json
file and recompile the app again, it was working similar to before deleting.
Solution:##
So, in that case, we'll have to delete the build
and .dart_tool
folder in our project folder,
Or run flutter clean
in terminal
and then recompile the app again from start.
I came to know about this after I wasted my 2 whole days, working in some other direction. That's why I had to share it, so that it doesn't happen to anybody else.
Firebase Database connection was forcefully killed by the server
If you updated google-services.json file.
-> Build / Clear Project
-> Rebuild Project
Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Firebase error. (Swift iOS)
You tagged with google-cloud-firestore
, but your code is accessing the Realtime Database. While both databases are part of Firebase, they are completely separate and the API for one will not work on the other.
So if you are indeed using Cloud Firestore, update your code to use the API to read from that database as shown here: https://firebase.google.com/docs/firestore/query-data/listen
iOS: Firebase: Database lives in a different region. Where to put the link?
You have to put that code wherever you are creating a reference to data from Firebase.
If you look at this code from step 3 of the Firebase documentation on setting up a connection to the database:
var ref: DatabaseReference!
ref = Database.database().reference()
This syntax creates a reference to the database as it is defined in your GoogleService-Info.plist
file.
Since you want to specify the URL in your code, you'd do:
var ref: DatabaseReference!
ref = Database.database("your database URL").reference()
And then use ref
everywhere else to read and write data.
You can alternatively also download an updated GoogleService-Info.plist
file from the Firebase console, and replace the one in your Xcode project with it. In that case the SDK will pick up the URL from the updated file.
Is there a way to fix the error Will not attempt reconnect. Reason: Database lives in a different region. in Android Studio with Firebase
You need to pass the URL every time you call FirebaseDatabase.getInstance()
, not just the first one.
So:
FirebaseDatabase db = FirebaseDatabase.getInstance("https://bioapps-customer-services-default-rtdb.asia-southeast1.firebasedatabase.app/");
db.getReference().child("RegData")
Alternatively, you can also download an up to date google-services.json
and drop that into your app. If the correct URL is in there, the SDK will read it from there when you call FirebaseDatabase.getInstance()
without arguments.
Related Topics
How to Use the Proguard in Android Studio
How to Use Data-Binding with Fragment
Aidl Is Missing Android Studio
Doze Mode and Foreground Service
Evenly Spacing Views Using Constraintlayout
Android What Permissions Required to Call Powermanager.Gotosleep(N) Put Device in Sleep Mode
Is My App or Its Dependencies Violating the Android Advertising Id Policy
Android Debug Monitor Hierarchy View Not Showing
How to Make a Edittext Box in a Dialog
Show Toast Widget Underneath a View
Best Way to Secure Android App Sensitive Data
How to Authenticate Two Types of Users (Student and Driver) in My Android App Using Firebase
When a Fragment Is Replaced and Put in the Back Stack (Or Removed) Does It Stay in Memory
Error:Please Fix the Version Conflict Either by Updating the Version of the Google-Services Plugin
How to Set Google Map Fragment Inside Scroll View
Error:Program Type Already Present: Android.Support.Design.Widget.Coordinatorlayout$Behavior