You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
4.0 KiB

  1. # A pure Go MSSQL driver for Go's database/sql package
  2. ## Install
  3. go get github.com/denisenkom/go-mssqldb
  4. ## Tests
  5. `go test` is used for testing. A running instance of MSSQL server is required.
  6. Environment variables are used to pass login information.
  7. Example:
  8. env HOST=localhost SQLUSER=sa SQLPASSWORD=sa DATABASE=test go test
  9. ## Connection Parameters
  10. * "server" - host or host\instance (default localhost)
  11. * "port" - used only when there is no instance in server (default 1433)
  12. * "failoverpartner" - host or host\instance (default is no partner).
  13. * "failoverport" - used only when there is no instance in failoverpartner (default 1433)
  14. * "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.
  15. * "password"
  16. * "database"
  17. * "connection timeout" - in seconds (default is 30)
  18. * "dial timeout" - in seconds (default is 5)
  19. * "keepAlive" - in seconds; 0 to disable (default is 0)
  20. * "log" - logging flags (default 0/no logging, 63 for full logging)
  21. * 1 log errors
  22. * 2 log messages
  23. * 4 log rows affected
  24. * 8 trace sql statements
  25. * 16 log statement parameters
  26. * 32 log transaction begin/end
  27. * "encrypt"
  28. * disable - Data send between client and server is not encrypted.
  29. * false - Data sent between client and server is not encrypted beyond the login packet. (Default)
  30. * true - Data sent between client and server is encrypted.
  31. * "TrustServerCertificate"
  32. * false - Server certificate is checked. Default is false if encypt is specified.
  33. * 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.
  34. * "certificate" - The file that contains the public key certificate of the CA that signed the SQL Server certificate. The specified certificate overrides the go platform specific CA certificates.
  35. * "hostNameInCertificate" - Specifies the Common Name (CN) in the server certificate. Default value is the server host.
  36. * "ServerSPN" - The kerberos SPN (Service Principal Name) for the server. Default is MSSQLSvc/host:port.
  37. * "Workstation ID" - The workstation name (default is the host name)
  38. * "app name" - The application name (default is go-mssqldb)
  39. * "ApplicationIntent" - Can be given the value "ReadOnly" to initiate a read-only connection to an Availability Group listener.
  40. Example:
  41. ```go
  42. db, err := sql.Open("mssql", "server=localhost;user id=sa")
  43. ```
  44. ## Statement Parameters
  45. In the SQL statement text, literals may be replaced by a parameter that matches one of the following:
  46. * ?
  47. * ?nnn
  48. * :nnn
  49. * $nnn
  50. where nnn represents an integer that specifies a 1-indexed positional parameter. Ex:
  51. ```go
  52. db.Query("SELECT * FROM t WHERE a = ?3, b = ?2, c = ?1", "x", "y", "z")
  53. ```
  54. will expand to roughly
  55. ```sql
  56. SELECT * FROM t WHERE a = 'z', b = 'y', c = 'x'
  57. ```
  58. ## Features
  59. * Can be used with SQL Server 2005 or newer
  60. * Can be used with Microsoft Azure SQL Database
  61. * Can be used on all go supported platforms (e.g. Linux, Mac OS X and Windows)
  62. * Supports new date/time types: date, time, datetime2, datetimeoffset
  63. * Supports string parameters longer than 8000 characters
  64. * Supports encryption using SSL/TLS
  65. * Supports SQL Server and Windows Authentication
  66. * Supports Single-Sign-On on Windows
  67. * Supports connections to AlwaysOn Availability Group listeners, including re-direction to read-only replicas.
  68. * Supports query notifications
  69. ## Known Issues
  70. * SQL Server 2008 and 2008 R2 engine cannot handle login records when SSL encryption is not disabled.
  71. To fix SQL Server 2008 R2 issue, install SQL Server 2008 R2 Service Pack 2.
  72. To fix SQL Server 2008 issue, install Microsoft SQL Server 2008 Service Pack 3 and Cumulative update package 3 for SQL Server 2008 SP3.
  73. More information: http://support.microsoft.com/kb/2653857