Skip to content
This repository was archived by the owner on Apr 24, 2026. It is now read-only.

Error AlreadyHasActiveConnectionError:Cannot create a new connection named 'default' #6

Description

@ahmadtlz

hi ,
the first time i reload the app (ctrl+m ==> reload )is work perfect but when i exit the app and again run it the warning popup
i wanna close the connection but i don't no how :(
this is my code in react-native App

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      savedPost: false, progress: 'Post is being saved', loadedPost: [],
      textDescription: '',
      title: '',
      category: '',
      birthDate: '1998-8-02',
      author: ''
    };
    this.runDemo();
  }


  connect() {
    return createConnection({
      type: 'react-native',
      database: 'test',
      location: 'default',
      logging: ['error', 'query', 'schema'],
      synchronize: true,
      entities: [
        Author,
        Category,
        Post
      ]
    });``


  async runDemo() {
    try {
      // SQLite.openDatabase({ name: 'my.db', location: 'Library' }, this.successCB, this.errorCB);
      await this.connect();


      const category1 = new Category();
      category1.name = "TypeScript";

      const category2 = new Category();
      category2.name = "Programming";

      const author = new Author();
      author.name = "Person";

      const post = new Post();
      post.title = "Control flow based type analysis";
      post.text = "TypeScript 2.0 implements a control flow-based type analysis for local  variables and parameters.";
      post.categories = [category1, category2];
      post.author = author;

      const postRepository = getRepository(Post);
      // await postRepository.save(post);

      console.log("Post has been saved");
      this.setState({
        progress: "Post has been saved"
      });

      const loadedPost = await postRepository.find({ id: Between('10', '12') });


      // createQueryBuilder('post')
      // .innerJoinAndSelect("post.author", "author")
      // .innerJoinAndSelect('post.categories', 'categories')
      // .where('post.id = :id', { id: post.id })
      // .getOne();

      if (loadedPost) {
        console.log("Post has been loaded: ", loadedPost);
        this.setState({
          loadedPost: loadedPost
        });
      }
    } catch (err) {
console.log(err)
  }

1

2

3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions