6

I am building the app with flutter and integrating the firebase. In the start, my app works completely fine but after some time a faced this problem firebase forcefully kill the connection between the app and the server.

W/PersistentConnection( 4812): pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to https://multiapp-f0e1e-default-rtdb.europe-west1.firebasedatabase.app

Talha Iqbal
  • 99
  • 1
  • 8

7 Answers7

22

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:

enter image description 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.

Madhav Kumar
  • 856
  • 8
  • 19
1

When you create a real-time database for the first time, DATABASE_URL is added to your config file (GoogleService-Info.plist & google-services.json) file on the server-side. You may be getting an error because the (GoogleService-Info.plist & google-services.json) is outdated and does not contain DATABASE_URL. You can download your updated (GoogleService-Info.plist & google-services.json) file from your Project Settings and try again.

Omar Mahmoud
  • 2,902
  • 1
  • 14
  • 22
0

Even after @Madhav's(accepted answer) solution didn't work, try creating a fresh project and follow the steps mentioned in accepted answer.

deZak
  • 109
  • 2
  • 2
0

Do like the first comment said after that just run the command flutter clean and build again and everything should work just fine!

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30945302) – David Salomon Feb 06 '22 at 06:15
0

make sure to delete build and .dart_tool folders, then it works

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '22 at 08:37
0

This is ALSO the error message if you are silly like me and are trying to connect to Google Girebase Database instead of what I actually had set up which is Google Firestore.

// Bad:
import 'package:firebase_database/firebase_database.dart';
DatabaseReference ref = FirebaseDatabase.instance.ref("users/123");


// Good
var db = FirebaseFirestore.instance;
import 'package:cloud_firestore/cloud_firestore.dart';

// (or vice versa)
0
FirebaseDatabase("your database URL").reference()

// Or

FirebaseDatabase(databaseURL: "your database URL").reference()

instead of

FirebaseDatabase.instance.reference()

Only for flutter users. It is happening because your database is outSide US servers.