Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: getting error "Cannot get connection "default" from connection manager." #39

Closed
bidipeppercrap opened this issue Sep 11, 2019 · 6 comments
Labels
type: question Questions about the usage of the library.

Comments

@bidipeppercrap
Copy link

bidipeppercrap commented Sep 11, 2019

TypeORM version: 0.2.18
Extension version: 0.2.3

await createConnection();

I'm using the default .env connection config.

@0x-leen
Copy link

0x-leen commented Jan 11, 2020

+1

1 similar comment
@Tsingbo-Kooboo
Copy link

+1

@mo-kalaleeb
Copy link

Same Issue, the following message appears:

Error: Cannot get connection "default" from the connection manager. Make sure you have created such conn
ection. Also make sure you have called useContainer(Container) in your application before you establishe
d a connection and importing any entity.

even when the code goes as follows:


    const loadedConnectionOptions = await getConnectionOptions();

    const connectionOptions = Object.assign(loadedConnectionOptions, {
        type: env.db.type as any, // See createConnection options for valid types
        host: env.db.host,
        port: env.db.port,
        username: env.db.username,
        password: env.db.password,
        database: env.db.database,
        synchronize: env.db.synchronize,
        logging: env.db.logging,
        entities: env.app.dirs.entities,
        migrations: env.app.dirs.migrations,
    });

    const connection = await createConnection(connectionOptions);

    if (settings) {
        settings.setData('connection', connection);
        settings.onShutdown(() => connection.close());
    }

@ethernal
Copy link

@MickSawy3r

I assume you figured it out but for others coming here:

Check this issue #487 (typeorm/typeorm#487) in index.ts add

typeorm.useContainer(typedi.Container);

I had the same error and it solved the problem.

@NoNameProvided NoNameProvided changed the title Cannot get connection "default" from connection manager. question: CCannot get connection "default" from connection manager. Jan 15, 2021
@NoNameProvided NoNameProvided added the type: question Questions about the usage of the library. label Jan 15, 2021
@NoNameProvided NoNameProvided changed the title question: CCannot get connection "default" from connection manager. question: getting error "Cannot get connection "default" from connection manager." Jan 15, 2021
@NoNameProvided
Copy link
Member

Cannot reproduce. As the docs and @ethernal says: you need to configure TypeORM to use the TypeDI container before you can use the decorators.

import { createConnection, useContainer } from 'typeorm';
import { Container } from 'typedi';

/** Tell TypeORM to use the TypeDI container to resolve it's dependencies. */
useContainer(Container);

/** Create a connection and start using TypeORM. */
createConnection({
  /* <connection options> */
}).catch(error => {
  console.error(`Couldn't connect to the database!`);
  console.error(error);
});

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

6 participants