In an application I have a globally scoped
var db *sql.DB
that is later called with
slcstrSource, slcint64Timestamp, slcstrContent, err := DB_functions.GetContent(db)
if err != nil {
fmt.Println("Error: " + err.Error())
}
GetContent is this:
func GetContent(db *sql.DB) ([]string, []int64, []string, error) {
var slcstrContent []string
var slcint64Timestamp []int64
var slcstrSource []string
// Run the query
rows, err := db.Query("SELECT source, timestamp, content FROM MyDatabase.MyTable")
if err != nil {
return slcstrSource, slcint64Timestamp, slcstrContent, err
}
defer rows.Close()
for rows.Next() {
// Holding variables for the content in the columns
var source, content string
var timestamp int64
// Get the results of the query
err := rows.Scan(&source, ×tamp, &content)
if err != nil {
return slcstrSource, slcint64Timestamp, slcstrContent, err
}
// Append them into the slices that will eventually be returned to the caller
slcstrSource = append(slcstrSource, source)
slcstrContent = append(slcstrContent, content)
slcint64Timestamp = append(slcint64Timestamp, timestamp)
}
return slcstrSource, slcint64Timestamp, slcstrContent, nil
}
When I run the application and these sections of code are hit, I get an:
Error: mssql: Invalid object name 'MyDatabase.MyTable'.
When I db.Ping() the database, it seems to work. From what I've narrowed down the error is happening right at the query, but I can't find what's wrong. I checked the database and there is a database called MyDatabase with a table called MyTable and the table has information in those three columns...
Is there something I'm missing before making the query, or in making the query?