Skip to content

How to handle 'Open connection failed:sql: unknown driver "mssql" (forgotten import?)'

Keith Hutchison edited this page Sep 8, 2016 · 3 revisions

The first time I ran https://github.com/denisenkom/go-mssqldb/blob/master/examples/simple.go I got the error 'Open connection failed:sql: unknown driver "mssql" (forgotten import?)'

I resolved this by changing import _ "github.com/denisenkom/go-mssqldb" to import "github.com/denisenkom/go-mssqldb"

Which gave a different error of 'imported and not used: "github.com/denisenkom/go-mssqldb" as mssql'.

However ... after changing back to import _ "github.com/denisenkom/go-mssqldb" and building again the first error went away.

I also had to change the main function name from 'simplemain' to 'main' for some reason before it would compile.

See http://stackoverflow.com/questions/39381968/why-would-open-connection-failedsql-unknown-driver-mssql-forgotten-import