I am trying to query data from SQL Server using Golang and GORM. But I am getting below error:-
DB Connection: &{{{0 0} 0 0 0 0} <nil> <nil> 0 0xc0000a4480 false 0 {0xc0000e5db0} <nil> {{0 0} {<nil>} map[] 0} 0xc00004c5b0 0xaccbe0 0xc00014d0a0 false <nil>}
HasTable- Currency: true
{CurrencyId:0 Code: Description:}
[35m(C:/Users/RahulBFL/Documents/architechbc/dot net/GORM/main.go:26)[0m
[33m[2019-12-27 15:56:13][0m [31;1m mssql: Invalid object name 'currencies'. [0m
My Table Schema looks like below:-
Currency
CurrencyId int
Code char
Description varchar
On SSMS, I am successfully able to query the table using the below command
select * from IMBookingApp.dbo.Currency
My Golang code
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mssql"
)
type Currency struct {
CurrencyId int
Code string
Description string
}
func main() {
db, err := gorm.Open("mssql", "sqlserver://USERNAME:PASSWORD@Endpoint:1433?database=DATABASENAME&Initial+Catalog=SCHEMA_NAME")
if err != nil {
fmt.Println("Connection Error:", err)
}
fmt.Println("DB Connection", db)
fmt.Println("HasTable- Currency:", db.HasTable("ClientUser"))
var Currency Currency
db.Find(&Currency)
fmt.Printf("%+v\n", Currency)
defer db.Close()
}
I don't understand why I am getting the error as - Invalid object name 'currencies'. Though there is no currencies in the schema, there is only currency.
Any help will be appreciated.