Cannot connect Hasura graphql with existing Microsoft SQL Server database

177 Views Asked by At

I am unable to connect hasura with already existing Microsoft SQL Server database. For testing purpose I have used a local Microsoft SQL Server database with:

  • server name: (LocalDb)\MSSQLLocalDB
  • user_name: user
  • password: pass

I have used the hasura cloud for connecting the existing database.

This is the database url:

Driver={ODBC Driver 18 for SQL Server};Server=tcp (LocalDb)\MSSQLLocalDB,1433;Database=tester;Uid=user;Pwd=password;Encrypt=optional

Error :

[
    {
        "definition": "Default",
        "message": {
            "exception": {
                "message": "[Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired",
                "type": "unsuccessful_return_code"
            }
        },
        "name": "source Default",
        "reason": "Inconsistent object: mssql connection error",
        "type": "source"
    }
]
1

There are 1 best solutions below

3
code-gijoe On

You could try to create yourself a docker compose file to test locally see if you can connect to a local DB, then set it to connect to remote DB.

Here is a sample Docker-compose file

services:
  postgres:
    image: postgis/postgis:12-master
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    command: [ "postgres", "-c", "wal_level=logical" ]
    volumes:
      - database-data:/var/lib/postgresql/data/

  hasura:
    image: hasura/graphql-engine:v2.30.1-ce.cli-migrations-v3.ubuntu
    ports:
      - "8080:8080"
    depends_on:
      - postgres
    command: /bin/sh -c 'sleep 20; graphql-engine serve'
    restart: always
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
      HASURA_GRAPHQL_JWT_SECRET: '{
                "type": "HS256",
                "key": "123"
            }'
      HASURA_GRAPHQL_ADMIN_SECRET: XXX

volumes:
  database-data:

I know this is using PG but it's pretty much the same process. Then you can change the variable HASURA_GRAPHQL_DATABASE_URL to set your DB credentials and connection