Okay so I reinstalled my PC a month ago and decided to get back to my api project. When I tried to run it, it gave me an error.
unable to open tcp connection with host 'localhost:1433': dial tcp [::1]:1433: connectex: No connection could be made because the target machine actively refused it.
which I don't understand why it's giving me this, I'm using MSSQL, I have it installed, I checked the database name, created the same database etc.
For context, I think these are the files that are most relevant
package main import ( "database/sql" "log" _ "github.com/denisenkom/go-mssqldb" "github.com/myGit/testGoApi/cmd/api" "github.com/myGit/testGoApi/db" ) fun...Okay so I reinstalled my PC a month ago and decided to get back to my api project. When I tried to run it, it gave me an error.
unable to open tcp connection with host 'localhost:1433': dial tcp [::1]:1433: connectex: No connection could be made because the target machine actively refused it.
which I don't understand why it's giving me this, I'm using MSSQL, I have it installed, I checked the database name, created the same database etc.
For context, I think these are the files that are most relevant
package main import ( "database/sql" "log" _ "github.com/denisenkom/go-mssqldb" "github.com/myGit/testGoApi/cmd/api" "github.com/myGit/testGoApi/db" ) func main() { db, err := db.NewMSSQLStorage() if err != nil { log.Fatal(err) } initStorage(db) server := api.NewAPIServer("0.0.0.0:8080", db) if err := server.Run(); err != nil { log.Fatal(err) } } func initStorage(db *sql.DB) { err := db.Ping() if err != nil { log.Fatal(err) } log.Println("DB: Successfully connected") } and
package db import ( "database/sql" "log" ) func NewMSSQLStorage() (*sql.DB, error) { connString := "server=localhost,1433;database=testDatabase;trusted_connection=yes" db, err := sql.Open("sqlserver", connString) if err != nil { log.Fatal("Failed to open DB:", err) } return db, nil } This all worked on my previous system. but now it doesn't. I don't know how to check what port my sql server is on, The way I understand it 1433 is the standard port for MSSQL so I don't know why it's not working.
edit, I tried connecting via powershell, I think, and it worked
but when I put this into the string, either localhost\\SQLEXPRESS or DE11\\SQLEXPRESS it throws the same error.
One more edit, me and my brother tried to connect to the database via C# console app in visual studio, and it worked. We used localhost\\SQLEXPRESS so I have no clue what is go's problem