{"id":37134306,"url":"https://github.com/brucecatyu/go-mssqldb","last_synced_at":"2026-01-14T15:40:13.508Z","repository":{"id":59046010,"uuid":"531810311","full_name":"BruceCatYu/go-mssqldb","owner":"BruceCatYu","description":"Microsoft SQL server driver written in go language","archived":false,"fork":true,"pushed_at":"2024-04-08T02:30:31.000Z","size":5569,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T05:02:42.393Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"denisenkom/go-mssqldb","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BruceCatYu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-02T06:36:18.000Z","updated_at":"2024-06-20T05:02:42.394Z","dependencies_parsed_at":"2023-01-20T14:18:26.507Z","dependency_job_id":null,"html_url":"https://github.com/BruceCatYu/go-mssqldb","commit_stats":null,"previous_names":["brucecatyu/go-mssqldb","2432001677/go-mssqldb"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/BruceCatYu/go-mssqldb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceCatYu%2Fgo-mssqldb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceCatYu%2Fgo-mssqldb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceCatYu%2Fgo-mssqldb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceCatYu%2Fgo-mssqldb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BruceCatYu","download_url":"https://codeload.github.com/BruceCatYu/go-mssqldb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BruceCatYu%2Fgo-mssqldb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28424374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T15:40:12.832Z","updated_at":"2026-01-14T15:40:13.501Z","avatar_url":"https://github.com/BruceCatYu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A pure Go MSSQL driver for Go's database/sql package\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/BruceCatYu/go-mssqldb.svg)](https://pkg.go.dev/github.com/BruceCatYu/go-mssqldb)\n[![Build status](https://ci.appveyor.com/api/projects/status/jrln8cs62wj9i0a2?svg=true)](https://ci.appveyor.com/project/BruceCatYu/go-mssqldb)\n[![codecov](https://codecov.io/gh/BruceCatYu/go-mssqldb/branch/master/graph/badge.svg)](https://codecov.io/gh/BruceCatYu/go-mssqldb)\n\nAppreciate to https://github.com/natefinch/npipe and https://github.com/simnalamburt/go-mssqldb  \n\nFor more recent updates, see the [Microsoft fork](https://github.com/microsoft/go-mssqldb).\n\n## Install\n\nRequires Go 1.8 or above.\n\nInstall with `go get github.com/BruceCatYu/go-mssqldb` .\n\n## Connection Parameters and DSN\n\nThe recommended connection string uses a URL format:\n`sqlserver://username:password@host/instance?param1=value\u0026param2=value`\nOther supported formats are listed below.\n\n### Common parameters\n\n* `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.\n* `password`\n* `database`\n* `connection 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.\n* `dial timeout` - in seconds (default is 15), set to 0 for no timeout\n* `encrypt`\n  * `disable` - Data send between client and server is not encrypted.\n  * `false` - Data sent between client and server is not encrypted beyond the login packet. (Default)\n  * `true` - Data sent between client and server is encrypted.\n* `app name` - The application name (default is go-mssqldb)\n\n### Connection parameters for ODBC and ADO style connection strings\n\n* `server` - host or host\\instance (default localhost)\n* `port` - used only when there is no instance in server (default 1433)\n\n### Less common parameters\n\n* `keepAlive` - in seconds; 0 to disable (default is 30)\n* `failoverpartner` - host or host\\instance (default is no partner).\n* `failoverport` - used only when there is no instance in failoverpartner (default 1433)\n* `packet size` - in bytes; 512 to 32767 (default is 4096)\n  * Encrypted connections have a maximum packet size of 16383 bytes\n  * Further information on usage: \u003chttps://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-network-packet-size-server-configuration-option\u003e\n* `log` - logging flags (default 0/no logging, 63 for full logging)\n  * 1 log errors\n  * 2 log messages\n  * 4 log rows affected\n  * 8 trace sql statements\n  * 16 log statement parameters\n  * 32 log transaction begin/end\n* `TrustServerCertificate`\n  * false - Server certificate is checked. Default is false if encrypt is specified.\n  * 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.\n* `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.\n* `hostNameInCertificate` - Specifies the Common Name (CN) in the server certificate. Default value is the server host.\n* `ServerSPN` - The kerberos SPN (Service Principal Name) for the server. Default is MSSQLSvc/host:port.\n* `Workstation ID` - The workstation name (default is the host name)\n* `ApplicationIntent` - Can be given the value `ReadOnly` to initiate a read-only connection to an Availability Group listener. The `database` must be specified when connecting with `Application Intent` set to `ReadOnly`.\n\n### The connection string can be specified in one of three formats\n\n1. URL: with `sqlserver` scheme. username and password appears before the host. Any instance appears as\n    the first segment in the path. All other options are query parameters. Examples:\n\n    * `sqlserver://username:password@host/instance?param1=value\u0026param2=value`\n    * `sqlserver://username:password@host:port?param1=value\u0026param2=value`\n    * `sqlserver://sa@localhost/SQLExpress?database=master\u0026connection+timeout=30` // `SQLExpress instance.\n    * `sqlserver://sa:mypass@localhost?database=master\u0026connection+timeout=30`     // username=sa, password=mypass.\n    * `sqlserver://sa:mypass@localhost:1234?database=master\u0026connection+timeout=30` // port 1234 on localhost.\n    * `sqlserver://sa:my%7Bpass@somehost?connection+timeout=30` // password is \"my{pass\"\n      A string of this format can be constructed using the `URL` type in the `net/url` package.\n\n    ```go\n\n    query := url.Values{}\n    query.Add(\"app name\", \"MyAppName\")\n    \n    u := \u0026url.URL{\n    \tScheme:   \"sqlserver\",\n    \tUser:     url.UserPassword(username, password),\n    \tHost:     fmt.Sprintf(\"%s:%d\", hostname, port),\n    \t// Path:  instance, // if connecting to an instance instead of a port\n    \tRawQuery: query.Encode(),\n    }\n    db, err := sql.Open(\"sqlserver\", u.String())\n\n    ```\n\n2. ADO: `key=value` pairs separated by `;`. Values may not contain `;`, leading and trailing whitespace is ignored.\n     Examples:\n\n    * `server=localhost\\\\SQLExpress;user id=sa;database=master;app name=MyAppName`\n    * `server=localhost;user id=sa;database=master;app name=MyAppName`\n\n    ADO strings support synonyms for database, app name, user id, and server\n    * server \u003c= addr, address, network address, data source\n    * user id \u003c= user, uid\n    * database \u003c= initial catalog\n    * app name \u003c= application name\n\n3. ODBC: Prefix with `odbc`, `key=value` pairs separated by `;`. Allow `;` by wrapping\n    values in `{}`. Examples:\n\n    * `odbc:server=localhost\\\\SQLExpress;user id=sa;database=master;app name=MyAppName`\n    * `odbc:server=localhost;user id=sa;database=master;app name=MyAppName`\n    * `odbc:server=localhost;user id=sa;password={foo;bar}` // Value marked with `{}`, password is \"foo;bar\"\n    * `odbc:server=localhost;user id=sa;password={foo{bar}` // Value marked with `{}`, password is \"foo{bar\"\n    * `odbc:server=localhost;user id=sa;password={foobar }` // Value marked with `{}`, password is \"foobar \"\n    * `odbc:server=localhost;user id=sa;password=foo{bar`   // Literal `{`, password is \"foo{bar\"\n    * `odbc:server=localhost;user id=sa;password=foo}bar`   // Literal `}`, password is \"foo}bar\"\n    * `odbc:server=localhost;user id=sa;password={foo{bar}` // Literal `{`, password is \"foo{bar\"\n    * `odbc:server=localhost;user id=sa;password={foo}}bar}` // Escaped `} with`}}`, password is \"foo}bar\"\n\n4. Choose a protocol\n* TCP (Omitting the protocol will defaults to TCP to preserve backward compatibility): server=localhost;user id=USER;password=PASSWORD;database=master\n\n* TCP: server=tcp:localhost;user id=USER;password=PASSWORD;database=master\n\n* Named pipe: server=np:\\\\.\\pipe\\sql\\query;user id=USER;password=PASSWORD;database=master\n\n* Shared Memory (It'll return \"not implemented yet\" error): server=lpc:.\\SQLEXPRESS;user id=USER;password=PASSWORD;database=master\n\n## Executing Stored Procedures\n\nTo run a stored procedure, set the query text to the procedure name:\n\n```go\n\nvar account = \"abc\"\n_, err := db.ExecContext(ctx, \"sp_RunMe\",\n\tsql.Named(\"ID\", 123),\n\tsql.Named(\"Account\", sql.Out{Dest: \u0026account}),\n)\n\n```\n\n## Reading Output Parameters from a Stored Procedure with Resultset\n\nTo read output parameters from a stored procedure with resultset, make sure you read all the rows before reading the output parameters:\n\n```go\n\nsqltextcreate := `\nCREATE PROCEDURE spwithoutputandrows\n\t@bitparam BIT OUTPUT\nAS BEGIN\n\tSET @bitparam = 1\n\tSELECT 'Row 1'\nEND\n`\nvar bitout int64\nrows, err := db.QueryContext(ctx, \"spwithoutputandrows\", sql.Named(\"bitparam\", sql.Out{Dest: \u0026bitout}))\nvar strrow string\nfor rows.Next() {\n\terr = rows.Scan(\u0026strrow)\n}\nfmt.Printf(\"bitparam is %d\", bitout)\n\n```\n\n## Caveat for local temporary tables\n\nDue to protocol limitations, temporary tables will only be allocated on the connection\nas a result of executing a query with zero parameters. The following query\nwill, due to the use of a parameter, execute in its own session,\nand `#mytemp` will be de-allocated right away:\n\n```go\nconn, err := pool.Conn(ctx)\ndefer conn.Close()\n_, err := conn.ExecContext(ctx, \"select @p1 as x into #mytemp\", 1)\n// at this point #mytemp is already dropped again as the session of the ExecContext is over\n```\n\nTo work around this, always explicitly create the local temporary\ntable in a query without any parameters. As a special case, the driver\nwill then be able to execute the query directly on the\nconnection-scoped session. The following example works:\n\n```go\nconn, err := pool.Conn(ctx)\n\n// Set us up so that temp table is always cleaned up, since conn.Close()\n// merely returns conn to pool, rather than actually closing the connection.\ndefer func() {\n\t_, _ = conn.ExecContext(ctx, \"drop table #mytemp\")  // always clean up\n\tconn.Close() // merely returns conn to pool\n}()\n\n\n// Since we not pass any parameters below, the query will execute on the scope of\n// the connection and succeed in creating the table.\n_, err := conn.ExecContext(ctx, \"create table #mytemp ( x int )\")\n\n// #mytemp is now available even if you pass parameters\n_, err := conn.ExecContext(ctx, \"insert into #mytemp (x) values (@p1)\", 1)\n\n```\n\n## Return Status\n\nTo get the procedure return status, pass into the parameters a\n`*mssql.ReturnStatus`. For example:\n\n```go\n\nvar rs mssql.ReturnStatus\n_, err := db.ExecContext(ctx, \"theproc\", \u0026rs)\nlog.Printf(\"status=%d\", rs)\n\n```\n\nor\n\n```go\nvar rs mssql.ReturnStatus\n_, err := db.QueryContext(ctx, \"theproc\", \u0026rs)\nfor rows.Next() {\n\terr = rows.Scan(\u0026val)\n}\nlog.Printf(\"status=%d\", rs)\n\n```\n\nLimitation: ReturnStatus cannot be retrieved using `QueryRow`.\n\n## Parameters\n\nThe `sqlserver` driver uses normal MS SQL Server syntax and expects parameters in\nthe sql query to be in the form of either `@Name` or `@p1` to `@pN` (ordinal position).\n\n```go\n\ndb.QueryContext(ctx, `select * from t where ID = @ID and Name = @p2;`, sql.Named(\"ID\", 6), \"Bob\")\n\n```\n\n### Parameter Types\n\nTo pass specific types to the query parameters, say `varchar` or `date` types,\nyou must convert the types to the type before passing in. The following types\nare supported:\n\n* string -\u003e nvarchar\n* mssql.VarChar -\u003e varchar\n* time.Time -\u003e datetimeoffset or datetime (TDS version dependent)\n* mssql.DateTime1 -\u003e datetime\n* mssql.DateTimeOffset -\u003e datetimeoffset\n* \"github.com/golang-sql/civil\".Date -\u003e date\n* \"github.com/golang-sql/civil\".DateTime -\u003e datetime2\n* \"github.com/golang-sql/civil\".Time -\u003e time\n* mssql.TVP -\u003e Table Value Parameter (TDS version dependent)\n\n## Important Notes\n\n* [LastInsertId](https://golang.org/pkg/database/sql/#Result.LastInsertId) should\n    not be used with this driver (or SQL Server) due to how the TDS protocol\n works. Please use the [OUTPUT Clause](https://docs.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql)\n or add a `select ID = convert(bigint, SCOPE_IDENTITY());` to the end of your\n query (ref [SCOPE_IDENTITY](https://docs.microsoft.com/en-us/sql/t-sql/functions/scope-identity-transact-sql)).\n This will ensure you are getting the correct ID and will prevent a network round trip.\n* [NewConnector](https://godoc.org/github.com/BruceCatYu/go-mssqldb#NewConnector)\n    may be used with [OpenDB](https://golang.org/pkg/database/sql/#OpenDB).\n* [Connector.SessionInitSQL](https://godoc.org/github.com/BruceCatYu/go-mssqldb#Connector.SessionInitSQL)\n may be set to set any driver specific session settings after the session\n has been reset. If empty the session will still be reset but use the database\n defaults in Go1.10+.\n\n## Features\n\n* Can be used with SQL Server 2005 or newer\n* Can be used on all go supported platforms (e.g. Linux, Mac OS X and Windows)\n* Supports new date/time types: date, time, datetime2, datetimeoffset\n* Supports string parameters longer than 8000 characters\n* Supports encryption using SSL/TLS\n* Supports SQL Server and Windows Authentication\n* Supports Single-Sign-On on Windows\n* Supports connections to AlwaysOn Availability Group listeners, including re-direction to read-only replicas.\n* Supports query notifications\n\n## Tests\n\n`go test` is used for testing. A running instance of MSSQL server is required.\nEnvironment variables are used to pass login information.\n\nExample:\n\n```bash\n    env SQLSERVER_DSN=sqlserver://user:pass@hostname/instance?database=test1 go test\n```\n\n## Deprecated\n\nThese features still exist in the driver, but they are are deprecated.\n\n### Query Parameter Token Replace (driver \"mssql\")\n\nIf you use the driver name \"mssql\" (rather then \"sqlserver\") the SQL text\nwill be loosly parsed and an attempt to extract identifiers using one of\n\n* ?\n* ?nnn\n* :nnn\n* $nnn\n\nwill be used. This is not recommended with SQL Server.\nThere is at least one existing `won't fix` issue with the query parsing.\n\nUse the native \"@Name\" parameters instead with the \"sqlserver\" driver name.\n\n## Known Issues\n\n* SQL Server 2008 and 2008 R2 engine cannot handle login records when SSL encryption is not disabled.\nTo fix SQL Server 2008 R2 issue, install SQL Server 2008 R2 Service Pack 2.\nTo fix SQL Server 2008 issue, install Microsoft SQL Server 2008 Service Pack 3 and Cumulative update package 3 for SQL Server 2008 SP3.\nMore information: \u003chttp://support.microsoft.com/kb/2653857\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrucecatyu%2Fgo-mssqldb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrucecatyu%2Fgo-mssqldb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrucecatyu%2Fgo-mssqldb/lists"}