在一個(gè)應(yīng)用程序中,我有一個(gè)全局范圍的var db *sql.DB后來(lái)被稱為slcstrSource, slcint64Timestamp, slcstrContent, err := DB_functions.GetContent(db) if err != nil { fmt.Println("Error: " + err.Error()) }GetContent 是這樣的: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}當(dāng)我運(yùn)行應(yīng)用程序并命中這些代碼部分時(shí),我得到:Error: mssql: Invalid object name 'MyDatabase.MyTable'.當(dāng)我 db.Ping() 數(shù)據(jù)庫(kù)時(shí),它似乎工作。從我縮小范圍來(lái)看,錯(cuò)誤發(fā)生在查詢中,但我找不到問(wèn)題所在。我檢查了數(shù)據(jù)庫(kù),有一個(gè)名為 MyDatabase 的數(shù)據(jù)庫(kù),其中有一個(gè)名為 MyTable 的表,該表在這三列中有信息......在進(jìn)行查詢之前或進(jìn)行查詢時(shí),我是否遺漏了什么?
Golang mssql 驅(qū)動(dòng)程序返回“mssql:無(wú)效的對(duì)象名稱”
繁星點(diǎn)點(diǎn)滴滴
2021-11-01 16:11:33