# Cannot connect to the ledger server, error: io.grpc.StatusRuntimeException: UNAVAILABLE: io exception

**URL:** <https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753>\
**Category:** App Development\
**Created:** [December 8, 2020, 7:35am UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753 "2020-12-08T07:35:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xuyx](https://avatars.discourse-cdn.com/v4/letter/x/cdc98d/32.png) [@Xuyx](https://forum.canton.network/u/Xuyx)\
**Post date:** [December 8, 2020, 7:35am UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/1 "2020-12-08T07:35:36Z")

</div>

I installed postgresql, and tried to startup with

```haskell
daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --query-store-jdbc-config "driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/postgres?&ssl=false,user=postgres,password=123qwe,createSchema=false"

```

It failed and exited.

```haskell
15:13:09.890 [main] INFO com.daml.http.Main$ - Config(ledgerHost=localhost, ledgerPort=6865,address=127.0.0.1, httpPort=7575, portFile=None, packageReloadInterval=5 seconds,packageMaxInboundMessageSize=None,maxInboundMessageSize=4194304,tlsConfig=TlsConfiguration(false,None,None,None,REQUIRE), jdbcConfig=Some(JdbcConfig(driver=org.postgresql.Driver, url=jdbc:postgresql://localhost:5432/postgres?&ssl=false, user=postgres, createSchema=false)), staticContentConfig=None, allowNonHttps=false, accessTokenFile=None, wsConfig=None)
15:13:10.194 [http-json-ledger-api-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
15:13:16.530 [http-json-ledger-api-akka.actor.default-dispatcher-13] ERROR com.daml.http.Main$ - Cannot start server: Error(Cannot connect to the ledger server, error: io.grpc.StatusRuntimeException: UNAVAILABLE: io exception)
15:13:16.582 [shutdownHook2] INFO com.daml.http.HttpService$ - Stopping server...
daml-helper: Received ExitFailure 101 when running
Raw command: java "-Dlogback.configurationFile=C:\\Users\\Xuyx\\AppData\\Roaming\\daml\\sdk\\1.7.0\\daml-sdk\\json-api-logback.xml" -jar "C:\\Users\\Xuyx\\AppData\\Roaming\\daml\\sdk\\1.7.0\\daml-sdk\\daml-sdk.jar" json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --query-store-jdbc-config driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/postgres?&ssl=false,user=postgres,password=123qwe,createSchema=false

```

What should I do to let it run successfully?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [December 8, 2020, 8:03am UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/2 "2020-12-08T08:03:23Z")

</div>

`Cannot connect to ledger server` means that the JSON API failed to connect to the underlying ledger, e.g., DAML on SQL. Do you have a ledger running? If so double check that it’s running on port 6865. If you don’t have a ledger running, you can use sandbox for development which you can start using `daml sandbox`. You might also be interested in `daml start` which will automatically start Sandbox and the JSON API to provide you with an easy development setup.

---

<div class="post-metadata">

**Author:** ![Xuyx](https://avatars.discourse-cdn.com/v4/letter/x/cdc98d/32.png) [@Xuyx](https://forum.canton.network/u/Xuyx)\
**Post date:** [December 8, 2020, 9:33am UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/3 "2020-12-08T09:33:30Z")

</div>

Thanks.I’m trying to let my project to go with database, and meet new problems.  
First, I try to add the following to daml.yaml, and run daml start

```haskell
sandbox-options:
- --wall-clock-time
- --ledgerid=Currency-sandbox
- --sql-backend-jdbcurl=jdbc:postgresql://localhost:5432/postgres?user=postgres&password=123qwe

```

It shows “ERROR: Shutting down because of an initialization error.  
org.flywaydb.core.api.FlywayException: Found non-empty schema(s) “public” but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.”

On the other hand, I run the followings,

```haskell
daml sandbox .daml\dist\Currency-1.0.0.dar --ledgerid=Currency-sandbox
daml json-api --ledger-host localhost --ledger-port 6865 --http-port 7575 --query-store-jdbc-config "driver=org.postgresql.Driver,url=jdbc:postgresql://localhost:5432/postgres?&ssl=false,user=postgres,password=123qwe,createSchema=true" --allow-insecure-tokens=true

```

and it told me at the front-end “JsonError: Cannot resolve template ID, given: Temp…a3f7018cf68ba885f8be25f6080617b),Currency,Issuer)”.  
All request failed at front-end.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [December 8, 2020, 2:19pm UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/4 "2020-12-08T14:19:00Z")

</div>

`Cannot resolve template ID` usually means that the template you are referencing has not been uploaded to the ledger. There can be various reasons for that:

1. Simple typos if you constructed the template id yourself.
2. Forgetting to upload the package.
3. Making a change to the DAML model after uploading it and rebuilding it. In that case, your client code will reference the template in the updated DAR while the ledger only knows about the original template. You have to upload the new DAR/restart the ledger with the new DAR.

I’m not quite sure about the first error, let me get back to you.

---

<div class="post-metadata">

**Author:** ![gerolf](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gerolf/32/358_2.png) [@gerolf](https://forum.canton.network/u/gerolf)\
**Post date:** [December 8, 2020, 3:28pm UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/5 "2020-12-08T15:28:14Z")

</div>

> [@Xuyx](#):
>
> It shows “ERROR: Shutting down because of an initialization error.  
> org.flywaydb.core.api.FlywayException: Found non-empty schema(s) “public” but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.”

Hi @Xuyx,  
This error basically says that you are running `daml sandbox` with a database that was previously running `daml sandbox-classic`. You’ll need to start with a fresh DB schema.

HTH

---

<div class="post-metadata">

**Author:** ![Xuyx](https://avatars.discourse-cdn.com/v4/letter/x/cdc98d/32.png) [@Xuyx](https://forum.canton.network/u/Xuyx)\
**Post date:** [December 9, 2020, 1:48am UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/6 "2020-12-09T01:48:56Z")

</div>

@gerolf. Thank you, my project run successfully after starting with a fresh DB schema.

---

<div class="post-metadata">

**Author:** ![Xuyx](https://avatars.discourse-cdn.com/v4/letter/x/cdc98d/32.png) [@Xuyx](https://forum.canton.network/u/Xuyx)\
**Post date:** [December 9, 2020, 2:38am UTC](https://forum.canton.network/t/cannot-connect-to-the-ledger-server-error-io-grpc-statusruntimeexception-unavailable-io-exception/1753/7 "2020-12-09T02:38:00Z")

</div>

Thanks. I solve it now. I missed “–sql-backend-jdbcurl” when I ran

```haskell
daml sandbox .daml\dist\Currency-1.0.0.dar --ledgerid=Currency-sandbox

```
