# Configuration + another Type Provider

**URL:** <https://forums.fsharp.org/t/configuration-another-type-provider/2089>\
**Category:** General\
**Tags:** beginners\
**Created:** [December 23, 2021, 11:16am UTC](https://forums.fsharp.org/t/configuration-another-type-provider/2089 "2021-12-23T11:16:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim108dev](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/jim108dev/32/1026_2.png) [@jim108dev](https://forums.fsharp.org/u/jim108dev)\
**Post date:** [December 23, 2021, 11:16am UTC](https://forums.fsharp.org/t/configuration-another-type-provider/2089/1 "2021-12-23T11:16:33Z")

</div>

Hi everybody,

I like to specify my db connection in a yaml config. So I followed

> **[PostgreSQL Provider](https://fsprojects.github.io/SQLProvider/core/postgresql.html)**
>
> Type providers for SQL server access.

> **[The YamlConfig type provider](https://fsprojects.github.io/FSharp.Configuration/YamlConfigProvider.html)**
>
> Type providers for the configuration of .NET projects.

On their own they work pretty good. Together it does not compile.

E.g:

```auto
open FSharp.Data.Sql

open FSharp.Configuration

[<Literal>]
let configPath = __SOURCE_DIRECTORY__ + "/" + "config.yaml" 

type Config = YamlConfig<configPath>
let config = Config()
let db = config.DB

//[<Literal>]
let connStr = $"User ID={db.UserId}..."

[<Literal>]
let connStrLiteral = "User ID=..."

type HR = SqlDataProvider<
            Common.DatabaseProviderTypes.POSTGRESQL, connStr,
            ResolutionPath = resolutionPath>

```

`connStrLiteral` works but it is hard-coded. With `connStr` I get

```auto
This is not a valid constant expression or custom attribute valueF# Compiler267

```

Do type providers not work in conjunction? Does somebody know a workaround?

Thank you!

---

<div class="post-metadata">

**Author:** ![jim108dev](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/jim108dev/32/1026_2.png) [@jim108dev](https://forums.fsharp.org/u/jim108dev)\
**Post date:** [December 23, 2021, 6:33pm UTC](https://forums.fsharp.org/t/configuration-another-type-provider/2089/2 "2021-12-23T18:33:04Z")

</div>

I figured a solution would be having a compile connection string which must be hard-coded and a runtime connection string which can be provided by the `YamlConfig`.

E.g.

```auto
[<Literal>]
let configPath = __SOURCE_DIRECTORY__ + "/config.yaml" 

[<Literal>]
let resolutionPath = "temp"

type Config = YamlConfig<configPath>
let config = Config()
let db = config.DB

type HR = SqlDataProvider<Common.DatabaseProviderTypes.POSTGRESQL, Env.DB.connStr, ResolutionPath = resolutionPath>

[<EntryPoint>]
let main argv =
    let runtimeConnectionString = db.RuntimeConnectionString
    let ctx = HR.GetDataContext runtimeConnectionString

```
