title: Golang Error with Backing up the DBmssql: BACKUP DATABASE is terminating abnormally
body: <p>I am trying to do a full backup for an MSSQL database using go.</p>
  
  <p>However, I tested the connection to the MSSQL server and it works like charm! </p>
  
  <p>By executing also a query into the code <code>SELECT @@VERSION</code> </p>
  
  <p>It gives me the version and that has been connected to mssql using the credentials in the code below. </p>
  
  <p>By running a query <code>BACKUP DATABASE name_db TO DISK = '/tmp/database.bak'</code> it fails with the following error </p>
  
  <blockquote>
    <p>Error with Backing up the DBmssql: BACKUP DATABASE is terminating abnormally</p>
  </blockquote>
  
  <p>I am sure that I am missing something, any ideas/thoughts would be much appreciated.</p>
  
  <p>BTW, I am on Ubuntu 16.04 and the mssql is installed there, I am using go version 1.9. </p>
  
  <p>This is my code:</p>
  
  <pre><code>package main                                                                    
    import (                                                                      
       _ "github.com/denisenkom/go-mssqldb"                                       
       "database/sql"                                                             
       "context"                                                                  
       "log"                                                                      
       "fmt" )                                                                    
  
  
  var server = "server_url"                                     
  var port = 1433                                                                 
  var user = "user"                                                          
  var password = "pass"                                                  
  
  var db *sql.DB                                                                  
  
  func main() {                                                                   
          var err error                                                                                                                                           
          // Create connection string                                               
          connString := fmt.Sprintf("server=%s;user id=%s;password=%s;
          port=%d", server, user, password, port)                                   
          // Create connection pool                                                 
          db, err = sql.Open("sqlserver", connString)                             
          if err != nil {                                                         
                  log.Fatal("Error creating connection pool: " 
                  + err.Error())     
          }                                                                       
       log.Printf("Connected!\n")                                                 
       defer db.Close()                                                           
  
          Backup()                                                                
          //Restore()                                                             
   }                                                                              
  
  func Backup(){                                                                  
          ctx := context.Background()                                                                                                                     
          err := db.PingContext(ctx)
          if err != nil {
                  log.Fatal("Error pinging database :( " + err.Error())
          }
          var result string
          err = db.QueryRowContext(ctx, "BACKUP DATABASE tempdb 
          TO DISK= '/tmp/Backup.bak' WITH NOFORMAT, NOINIT,
          SKIP, NOREWIND, NOUNLOAD, STATS = 10;").Scan(&amp;result)
          //err = db.QueryRowContext(ctx, "select @@version").Scan(&amp;result)
          if err != nil {
                  log.Fatal("Error with Backing up the DB", err.Error())
          }
          fmt.Printf("%s\n",result)
  
  }   
  </code></pre>
  
  <p>I have found the solution which is very silly.. You can find it in the 1st reply.</p>