Go: SQL Server database sql connection

Demonstrates executing a SQL INSERT statement by opening and closing a connection to Cloud SQL for SQL Server using Go's database/sql package.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


sqlInsert := "INSERT INTO votes (candidate, time_cast) VALUES (?, GETDATE())"
if team == "TABS" || team == "SPACES" {
	if _, err := app.db.Exec(sqlInsert, team); err != nil {
		fmt.Fprintf(w, "unable to save vote: %s", err)
		return fmt.Errorf("DB.Exec: %v", err)
	fmt.Fprintf(w, "Vote successfully cast for %s!\n", team)
return nil

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.