fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

Cannot connect to a local SQL database on NET5 w/ SSDT #725

Closed isaacabraham closed 3 years ago

isaacabraham commented 3 years ago
  1. Create a database.
  2. Connect using following syntax:
[<Literal>]
let dbVendor = Common.DatabaseProviderTypes.MSSQLSERVER_SSDT

[<Literal>]
let SsdtPath = __SOURCE_DIRECTORY__ + @"/../Database/bin/Debug/Database.dacpac"

type DB = SqlDataProvider<Common.DatabaseProviderTypes.MSSQLSERVER_SSDT, SsdtPath = SsdtPath>

let ctx = DB.GetDataContext(@"<connection_string_goes_here>")

We tried to add a row to a table and got the following error:

Unhandled exception. System.TypeInitializationException: The type initializer for 'SqlProvider' threw an exception.
 ---> System.TypeInitializationException: The type initializer for '<StartupCode$TestProject>.$SqlProvider' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at FSharp.Data.Sql.Providers.MSSqlServerProviderSsdt..ctor(String tableNames, String ssdtPath)
   at FSharp.Data.Sql.Runtime.ProviderBuilder.createProvider(DatabaseProviderTypes vendor, String resolutionPath, String[] referencedAssemblies, String runtimeAssembly, String owner, String tableNames, String contextSchemaPath, OdbcQuoteCharacter odbcquote, SQLiteLibrary sqliteLibrary, String ssdtPath)
   at <StartupCode$FSharp-Data-SqlProvider>.$SqlRuntime.DataContext.addCache@38-1.Invoke(Unit unitVar)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at FSharp.Data.Sql.Runtime.SqlDataContext..ctor(String typeName, String connectionString, DatabaseProviderTypes providerType, String resolutionPath, String[] referencedAssemblies, String runtimeAssembly, String owner, CaseSensitivityChange caseSensitivity, String tableNames, String contextSchemaPath, OdbcQuoteCharacter odbcquote, SQLiteLibrary sqliteLibrary, TransactionOptions transactionOptions, FSharpOption`1 commandTimeout, SelectOperations sqlOperationsInSelect, String ssdtPath)
   at <StartupCode$TestProject>.$SqlProvider..cctor() in C:\Users\isaac\code\TestProject\Test\SqlProvider.fs:line 13
   --- End of inner exception stack trace ---
   at SqlProvider..cctor()
   --- End of inner exception stack trace ---

Not sure how to fix this.

JordanMarr commented 3 years ago

Did you manually add the System.Data.SqlClient package?

isaacabraham commented 3 years ago

Closing, that was exactly the issue.