Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSN parameter in connection string #532

Closed
manawasp opened this issue Oct 23, 2019 · 4 comments
Closed

DSN parameter in connection string #532

manawasp opened this issue Oct 23, 2019 · 4 comments

Comments

@manawasp
Copy link

manawasp commented Oct 23, 2019

Hello,

I try to play with mssql in Golang, moving some code from python.
In python, I was using pyodbc (pyodbc DSN doc) and my connection string looks like this :

pyodbc.connect('DSN=MSDB-DV-1-SQL,DATABASE=MYAPP_DB')

Which is working, so I just translated it in Go but it doesn't work I guess I miss something :/

package main

import (
	"database/sql"
	"flag"
	"fmt"
	"log"

	_ "github.com/denisenkom/go-mssqldb"
)

var (
	debug = flag.Bool("debug", false, "enable debugging")
	dsn   = flag.String("dsn", "", "the database dsn")
	db    = flag.String("database", "", "the database user")
)

func main() {
	flag.Parse()

	connString := fmt.Sprintf("DSN=%s;DATABASE=%s", *dsn, *db)
	if *debug {
		fmt.Printf(" connString:%s\n", connString)
	}
	conn, err = sql.Open("mssql", connString)
	if err != nil {
		log.Fatal("2. Open connection failed:", err.Error())
	}
	defer conn.Close()
...

I adapted this code from the simple.go file.

$ ./main --dsn="MSDB-DV-1-SQL" --database="MYAPP_DB" --debug=true
 connString:DSN=MSDB-DV-1-SQL;DATABASE=MYAPP_DB
2019/10/23 12:12:31 Prepare failed:Unable to open tcp connection with host 'localhost:1433': dial tcp 127.0.0.1:1433: connect: connection refused

Do you have an idea if it possible to connect using those parameters?

Thanks !

@chris-rossi
Copy link
Contributor

Hi @manawasp, it is possible to connect with those parameters and I have confirmed this using my own dsn. Can you confirm the connection information in your dsn is correct. Also in the error message it seems to be trying to connect to localhost on port 1433, is this what you have in your DSN? Finally what authentication type are you using to connect?

@manawasp
Copy link
Author

manawasp commented Nov 3, 2019

Hi, thanks for your answer I will do some tests.
I'm using Kerberos for the authentication

@chris-rossi
Copy link
Contributor

@manawasp, are you able to connect using connection string parameters instead of a DSN with the Go driver?

@manawasp
Copy link
Author

Hey @chris-rossi sorry for the very late answer,

I'm pretty sure my issue is related to this one: #383 and see there is PR under review: #702
So I will close this!

Thanks for your time and if you need some people to perform tests don't hesitate to notify me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants