microsoft/go-mssqldb
forked from denisenkom/go-mssqldb
Captured source
source ↗microsoft/go-mssqldb
Description: Microsoft SQL server driver written in go language
Language: Go
License: BSD-3-Clause
Stars: 407
Forks: 99
Open issues: 52
Created: 2022-03-30T14:10:52Z
Pushed: 2026-08-08T02:37:22Z
Default branch: main
Fork: yes
Parent repository: denisenkom/go-mssqldb
Archived: no
README:
Microsoft's official Go MSSQL driver
  
A pure Go database/sql driver for Microsoft SQL Server and Azure SQL Database. This is the recommended Go SQL Server driver for connecting Go applications to SQL Server, Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics.
Keywords: golang sql server driver, go mssql, azure sql go, go-mssqldb, sql server golang, mssql go driver
Install
Requires Go 1.25 or above.
Install with go get github.com/microsoft/go-mssqldb@latest.
Connection Parameters and DSN
The recommended connection string uses a URL format: sqlserver://username:password@host/instance?param1=value¶m2=value Other supported formats are listed below.
All connection string parameters are case-insensitive. Providing the same parameter more than once with different casing (e.g., TrustServerCertificate and trustservercertificate) will result in a parse error.
Common parameters
user id- enter the SQL Server Authentication user id or the Windows Authentication user id in the DOMAIN\User format. On Windows, if user id is empty or missing Single-Sign-On is used. The user domain sensitive to the case which is defined in the connection string.passworddatabaseconnection timeout- in seconds (default is 0 for no timeout), set to 0 for no timeout. Recommended to set to 0 and use context to manage query and connection timeouts.dial timeout- in seconds (default is 15 times the number of registered protocols), set to 0 for no timeout.encryptstrict- Data sent between client and server is encrypted E2E using TDS8.disable- Data send between client and server is not encrypted.false/optional/no/0/f- Data sent between client and server is not encrypted beyond the login packet. (Default)true/mandatory/yes/1/t- Data sent between client and server is encrypted.app name- The application name (default is go-mssqldb)authenticator- Can be used to specify use of a registered authentication provider. (e.g. ntlm, winsspi (on windows) or krb5 (on linux))timezone- Sets the time zone used by the driver when parsing time types. For example:timezone=Asia/Shanghai. Supports IANA time zone names.
Connection parameters for ODBC and ADO style connection strings
server- host or host\instance (default localhost)port- specifies the host\instance port (default 1433). If instance name is provided but no port, the driver will use SQL Server Browser to discover the port.
Less common parameters
keepAlive- in seconds; 0 to disable (default is 30)failoverpartner- host or host\instance (default is no partner).failoverport- used only when there is no instance in failoverpartner (default 1433)failoverpartnerspn- The kerberos SPN (Service Principal Name) for the failover partner. Default is MSSQLSvc/host:(port|instance), matching how the driver generatesServerSPN.packet size- in bytes; 512 to 32767 (default is 4096)- Encrypted connections have a maximum packet size of 16383 bytes
- Further information on usage:
log- logging flags (default0/no logging,255for full logging)1log errors2log messages4log rows affected8trace sql statements16log statement parameters32log transaction begin/end64additional debug logs128log retriesTrustServerCertificate- false - Server certificate is checked. Default is false if encrypt is specified.
- true - Server certificate is not checked. Default is true if encrypt is not specified. If trust server certificate is true, driver accepts any certificate presented by the server and any host name in that certificate. In this mode, TLS is susceptible to man-in-the-middle attacks. This should be used only for testing.
certificate- The file path to a certificate authority (CA) certificate or server certificate for traditional X.509 chain validation. The specified certificate overrides the go platform specific CA certificates. The driver validates the certificate chain, expiry, and hostname. Supports PEM and DER formats.serverCertificate- The file path to a server certificate for byte-for-byte comparison validation (new in v1.9.6). The driver validates that the server's certificate exactly matches this file, skipping chain validation, expiry checks, and hostname validation. This matches Microsoft.Data.SqlClient behavior. Cannot be used withcertificateorhostnameincertificate. Supports PEM and DER formats.hostNameInCertificate- Specifies the Common Name (CN) in the server certificate. Default value is the server host. Used with thecertificateparameter, not applicable forserverCertificate.tlsmin- Specifies the minimum TLS version for negotiating encryption with the server. Recognized values are1.0,1.1,1.2,1.3. If not set to a recognized value the default value for thetlspackage will be used. The default is currently1.2.ServerSPN- The kerberos SPN (Service Principal Name) for the server. Default is MSSQLSvc/host:port.Workstation ID- The workstation name (default is the host name)ApplicationIntent- Can be given the valueReadOnlyto initiate a read-only connection to an Availability Group listener. Thedatabasemust be specified when connecting withApplication Intentset toReadOnly.protocol- forces use of a protocol. Make sure the corresponding package is imported.columnencryptionorcolumn encryption setting- a boolean value indicating whether...
Excerpt shown — open the source for the full document.