Unable to read connection string from app.config

Open
#625 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
postgresql
Domain
databases

Research direction

Start with src/SQLProvider/Utils.fs, especially getConStringFromConfig and the referenced line that reads the connection string. Follow the attached example's docker-compose, restore, and build steps to reproduce the failure. Done means the provider successfully connects using the connection string from app.config instead of requiring it in source or at runtime.

Written by the indexing model from the issue text.

Description

question
Description

I'm attempting to specify the connection string to my DB in an app.config file in the root of my project, instead of hardcoding it in source. The type provider throws the following error:

No connection string specified or could not find a connection string with name DefaultConnectionString

I've read through the Utils.fs file, specifically the getConStringFromConfig function. I can see that line 235 reads match config.ConnectionStrings.ConnectionStrings.[connectionStringName]. Not sure if the double ConnectionStrings is intended? That said, I've tried a few variations of nesting in my app.config file with no luck.

Repro steps
  1. Download and extract the attached example
  2. cd to root directory of example
  3. docker-compose up
  4. dotnet restore
  5. dotnet build
Expected behavior

Successful connection to DB using connection string defined in app.config.

Actual behavior

The compiler throws the following error:

No connection string specified or could not find a connection string with name DefaultConnectionString

Known workarounds
  1. Hardcode the connection string in source
  2. Provide a connection string at runtime using .GetDataContext connString (though doesn’t help where compilation needs to happen across differing environments)
Related information
  • Used database: Postgres
  • Operating system: MacOS and Windows 10 (tested on both)
  • Branch: master
  • .NET Runtime, CoreCLR or Mono Version: assuming CoreCLR - not sure how to be certain?
  • Performance information, links to performance testing scripts:

ConnectionStringTest.zip

Dominant language
F#
Stars
627
Forks
147
Avg merge
2h 2m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fsprojects/SQLProvider

All issues in fsprojects/SQLProvider

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.