Hello all,
I am using Golang to create a web app that connects to the same MS SQL database as a desktop app. There is a database procedure, GetNextID, which is used to generate the next ID of various sorts. When I run the following code in the Microsoft SQL Server Management Studio, it properly increments the counter for the CalendarID, and returns the next ID:
DECLARE @NewCalendarID int; EXEC @NewCalendarID = GetNextID @StationID=44, @CounterID=13; SELECT @NewCalendarID;
However, when I run the above code as a Go query, it increments the counter but does not return any rows. Here is my code:
/* find the next CalendarID */
queryString = "DECLARE @NewCalendarID int; EXEC @NewCalendarID = GetNextID @StationID=44, @CounterID=13; SELECT @NewCalendarID AS NewCalendarID;"
/* Execute the query */
_, err = fldb.Exec("USE " + sqlDB)
if err != nil {
log.Println("Error in USE statement (finding the next CalendarID): " + err.Error())
return err
}
rows, err := fldb.Query(queryString)
if err != nil {
log.Println("Error executing query (finding the next CalendarID): " + queryString + " : " + err.Error())
return err
}
if rows.Next() {
err = rows.Scan(&newCalID)
if err != nil {
log.Println("Error scanning data (finding the next CalendarID): " + queryString + " : " + err.Error())
return err
}
calID = strconv.Itoa(int(newCalID))
} else {
log.Println("No rows returned (finding the next CalendarID): " + queryString)
}
I expect I am doing something wrong, but I can't figure out what. Any ideas?
Thanks in advance,
Renee