# SQLParseException when opening CrateDB connection in C#

**URL:** <https://community.cratedb.com/t/sqlparseexception-when-opening-cratedb-connection-in-c/436>\
**Category:** Integrations\
**Created:** [June 18, 2020, 7:23pm UTC](https://community.cratedb.com/t/sqlparseexception-when-opening-cratedb-connection-in-c/436 "2020-06-18T19:23:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandervandevelde](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/sandervandevelde/32/174_2.png) [@sandervandevelde](https://community.cratedb.com/u/sandervandevelde)\
**Post date:** [June 18, 2020, 7:23pm UTC](https://community.cratedb.com/t/sqlparseexception-when-opening-cratedb-connection-in-c/436/1 "2020-06-18T19:23:04Z")

</div>

I get this exception when I open the C# connection to my database:

> Npgsql.PostgresException: ‘XX000: SQLParseException: line 2:51: mismatched input ‘READ’ \>expecting {, ‘;’}’  
> This exception was originally thrown at this call stack:  
> [External Code]  
> CrateDBClient.Program.SaveLocation(CrateDBClient.Location) in Program.cs  
> CrateDBClient.Program.Main(string) in Program.cs

The code I execute:

```
// Host -> sudo nano /etc/hostname ; and check if pingable on other device
using (var conn = new NpgsqlConnection("Host=ark1123;Username=edgeingest;Password=p@ssw0rd"))
{
  conn.Open(); <- fails on this row
  // Insert some data

```

It fails when I open the connection in C# (using the latest crate nuget package).

```
<PackageReference Include="Npgsql.CrateDB" Version="1.2.3" />

```

I have a Linux machine which runs the Crate container and port 5432 and 4200 are opened. (hostname is ark1123).

The table is created with:

```
CREATE TABLE iss (timestamp TIMESTAMP GENERATED ALWAYS AS CURRENT_TIMESTAMP,position GEO_POINT)
CREATE USER edgeingest WITH (password = 'p@ssw0rd');
GRANT ALL to edgeingest;

```

On the machine running the C# code, I can reach the admin portal.

What is happening?

Sander

---

<div class="post-metadata">

**Author:** ![sandervandevelde](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/sandervandevelde/32/174_2.png) [@sandervandevelde](https://community.cratedb.com/u/sandervandevelde)\
**Post date:** [June 23, 2020, 6:11am UTC](https://community.cratedb.com/t/sqlparseexception-when-opening-cratedb-connection-in-c/436/2 "2020-06-23T06:11:06Z")

</div>

I found out I was missing the line

```
NpgsqlDatabaseInfo.RegisterFactory(new CrateDbDatabaseInfoFactory());

```

Once added, I was able to run queries.

I noticed that the connectionstring also works without providing the password.

What is the common way to secure access to tables?

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [June 23, 2020, 10:04am UTC](https://community.cratedb.com/t/sqlparseexception-when-opening-cratedb-connection-in-c/436/3 "2020-06-23T10:04:40Z")

</div>

The default configuration (crate.yml) coming with docker images uses a simplified version of the standard configuration file ([https://github.com/crate/crate/blob/master/app/src/main/dist/config/crate.yml](https://github.com/crate/crate/blob/master/app/src/main/dist/config/crate.yml)).

HBA (Host Based Authentication) is disabled by default

> **[Host-Based Authentication (HBA)](https://cratedb.com/docs/crate/reference/en/5.5/admin/auth/hba.html)**
>
> This section explains how to configure CrateDB client connection and authentication. Table of contents Authentication against CrateDB, Authenticating as a superuser, Authenticating to Admin UI, Node-to-node communication. Authentication against...

> By default, the boolean setting `auth.host_based.enabled` is `false` and therefore host based authentication is disabled. In this instance, the CrateDB cluster allows any unauthenticated connections.

With the standard configuration you wouldn’t be able to connect to crateDB running in a Docker container unless you would start a terminal session within the container (localhost).

After setting up an inital user, you should adapt the crate.yml and activate HBA. with something like

```auto
auth.host_based.enabled: true

auth:
  host_based:
    config:
      0:
        user: crate
        address: _local_
        method: trust
      99:
        method: password
`
``

then you can only connect using a user/pwd combination from outside the docker container.
```
