title: TSQL - An object or column name is missing or empty .. When trying to backup sql server database to disk
body: <blockquote>
  <p>My Connection String in which error occurs</p>
  </blockquote>
  <pre><code>&lt;add name=&quot;SmartSales_local&quot; connectionString=&quot;Server=.\SQLEXPRESS;Integrated Security=true;AttachDbFileName=|DataDirectory|\SmartSales.mdf;&quot;
            providerName=&quot;System.Data.SqlClient&quot; /&gt;
  </code></pre>
  <blockquote>
  <pre><code>My Database Backup Code in C#
  </code></pre>
  </blockquote>
  <pre><code>            con.ConnectionString = MyConnection();
              String receiptdir = @&quot;D:\SmatSalesReports\Backup&quot;;
              if (!Directory.Exists(receiptdir))
              {
                  Directory.CreateDirectory(receiptdir);
              }
              string dbname = con.Database.ToString();
              
              string backupdb = &quot;BACKUP DATABASE [&quot; + dbname + &quot;] TO DISK='&quot; + receiptdir + &quot;\\&quot; + &quot;SmartSales&quot; + &quot;-&quot; + DateTime.Now.ToString(&quot;yyyy-MM-dd--HH-mm-ss&quot;) + &quot;.bak'&quot;;
              
              
              con.Open();
              cm = new SqlCommand(backupdb, con);
              cm.CommandTimeout = 120;
              cm.ExecuteNonQuery();
              con.Close();
  </code></pre>
  <p>I am getting this error while trying to backup sql server database to disk. Everything else works fine &quot;inserting/Updating/deleting&quot; in the database.
  It gives me this error when I try to backup the database.
  <a href="https://i.stack.imgur.com/Qf7bE.png" rel="nofollow noreferrer">Screenshot of the error described</a></p>
  <blockquote>
  <p>An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as &quot;&quot; or [] are not allowed. Change the alias to a valid name.</p>
  </blockquote>
  <p><strong>New Information added after edit</strong></p>
  <blockquote>
  <p>My Connection String in which everything works fine</p>
  </blockquote>
  <pre><code>&lt;add name=&quot;SmartSales&quot; connectionString=&quot;Data Source=LAPTOP-GPJ5DM2V\SQLEXPRESS;Initial Catalog=SmartSales;Integrated Security=True&quot;
        providerName=&quot;System.Data.SqlClient&quot; /&gt;
  </code></pre>
  <p>When I use this connection string everything works fine. But it works when SSMS is installed and the DB is opened in SSMS.</p>