ODBC
DSN
Configuring DSN on Windows ODBC Data Source Administrator server: Control Panel -> Administrative Tools -> Data Sources (ODBC) (or launch: c:\windows\syswow64\odbcad32.exe) and add your driver to DSN.
open FSharp.Data.Sql
[<Literal>]
let dnsConn = @"DSN=foo"
type db = SqlDataProvider<Common.DatabaseProviderTypes.ODBC, dnsConn>
let ctx = db.GetDataContext()
You don't need DSN for all data sources, e.g. MS Access can be used directly
through the database file with a connection string like:
@"Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\Northwind.mdb"
Quote Character
Because there are a lot of different kind of ODBC connection types, you can set quote characters for SQL-clauses with optional parameter OdbcQuote.
OdbcQuoteCharacter.SQUARE_BRACKETS
OdbcQuoteCharacter.GRAVE_ACCENT
OdbcQuoteCharacter.NO_QUOTES
OdbcQuoteCharacter.DOUBLE_QUOTES
OdbcQuoteCharacter.APHOSTROPHE
and the difference in executed SQL is:
|
[<Literal>]
let quotechar = FSharp.Data.Sql.Common.OdbcQuoteCharacter.DEFAULT_QUOTE
type db2 = SqlDataProvider<Common.DatabaseProviderTypes.ODBC, dnsConn, OdbcQuote = quotechar>
let ctx2 = db2.GetDataContext()
DTC Transactions
SQLProvider will do DTC-transactions over CRUD-operations. That will ensure
that all the database operations will either succeed or fail at once; when you do
ctx.SubmitUpdates()
.
However, some ODBC-drivers (like MS-Access) don't support DTC-transactions and will fail on the constructor call. The transaction creation can be disabled in context creation:
let ctx3 =
db.GetDataContext(
{ Timeout = TimeSpan.MaxValue;
IsolationLevel = Transactions.IsolationLevel.DontCreateTransaction
}:FSharp.Data.Sql.Transactions.TransactionOptions)
Don't disable transactions if you don't need to.
type LiteralAttribute = inherit Attribute new: unit -> LiteralAttribute
--------------------
new: unit -> LiteralAttribute
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp.Data
--------------------
namespace Microsoft.FSharp.Data
<summary>Typed representation of a database</summary> <param name='ConnectionString'>The connection string for the SQL database</param> <param name='ConnectionStringName'>The connection string name to select from a configuration file</param> <param name='DatabaseVendor'> The target database vendor</param> <param name='IndividualsAmount'>The amount of sample entities to project into the type system for each SQL entity type. Default 50. Note GDPR/PII regulations if using individuals with ContextSchemaPath.</param> <param name='UseOptionTypes'>If set, F# option types will be used in place of nullable database columns. If not, you will always receive the default value of the column's type even if it is null in the database.</param> <param name='ResolutionPath'>The location to look for dynamically loaded assemblies containing database vendor specific connections and custom types. Types used in desing-time: If no better clue, prefer .NET Standard 2.0 versions. Semicolon to separate multiple.</param> <param name='Owner'>Oracle: The owner of the schema for this provider to resolve. PostgreSQL: A list of schemas to resolve, separated by spaces, newlines, commas, or semicolons.</param> <param name='CaseSensitivityChange'>Should we do ToUpper or ToLower when generating table names?</param> <param name='TableNames'>Comma separated table names list to limit a number of tables in big instances. The names can have '%' sign to handle it as in the 'LIKE' query (Oracle and MSSQL Only)</param> <param name='ContextSchemaPath'>The location of the context schema previously saved with SaveContextSchema. When not empty, will be used to populate the database schema instead of retrieving it from then database.</param> <param name='OdbcQuote'>Odbc quote characters: Quote characters for the table and column names: `alias`, [alias]</param> <param name='SQLiteLibrary'>Use System.Data.SQLite or Mono.Data.SQLite or select automatically (SQLite only)</param> <param name='SsdtPath'>A path to an SSDT .dacpac file.'</param>
<summary> Corresponds to the System.Transactions.IsolationLevel. </summary>
<summary> Corresponds to the System.Transactions.TransactionOptions. </summary>