Get result from SQL Server stored procedure [SOLVED]

Hey guys, I’m trying to get result from a SQL Server stored procedure but I always get the following error;

In my case it’s SQL Server, but I’m reading here many other people complainments with other databases too, such as MySQL and Oracle, people getting the same issue… Searching a bit more I saw that it’s a GO limitation. How can I handle on this? My procedure returns for example;

SELECT -1 AS RESULT

Or other values, depending on what happens inside the procedure, and always with the alias RESULT… Below is my try;

	var ret int
	sqlstr2 := "EXEC PRCENVIACOMANDO @IDVEICULO=" + urlqry.Get("idveiculo") + ", @CMD=2"
	err2:= db.QueryRow(sqlstr2).Scan(&ret)
	if err2 != nil {
		GeraLog(err2.Error())
		return
	}

My procedure executes, but I can’t get the result.

Appreciate any kind of help. Tnx.

Hi @leogazio,

I’m not sure if it’s contributing to the problem you are having but I will suggest using placeholder parameters in the QueryRow function instead of a self formatted string.

Try changing this:

sqlstr2 := "EXEC PRCENVIACOMANDO @IDVEICULO=" + urlqry.Get("idveiculo") + ", @CMD=2"
err2:= db.QueryRow(sqlstr2).Scan(&ret)

to this:

err2:= db.QueryRow( "EXEC PRCENVIACOMANDO @IDVEICULO=?, @CMD=?",urlqry.Get("idveiculo") ,2).Scan(&ret)
1 Like

Something else I would like to mention is to look at using Named parameters(go1.8) and Out(go1.9) when working with stored procedures. The Go mssql driver have support for these.

1 Like

Delete my post? Why?

Hi, no it doens’t resolve my problem.

I could never connect to my database using that driver, no matter what conncetion string I use, I never connected.

Hey there, I resolved my problem by adding “set nocount on;” before my procedure call, I never needed to do it with no other language, but that did the trick. If any one needs this someday, that’s how I resolved.

1 Like

Interesting - what driver are you using for MS SQL ?

1 Like

alexbrainman/odbc

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.