title: DateTime sent in wrong format to Sql Server 2014
body: <p>I'd like to execute a stored procedure on an sql server 2014. The sql server is set up in German, the user used for connecting to the sql server has also configured German as language. If I try to execute the sql procedure or raw sql, I always get the error </p>
  
  <blockquote>
    <p>varchar cannot be converted to datetime</p>
  </blockquote>
  
  <p>even if I provide german datetime values. I've found out that it works if I prepend the sql text with the command <code>SET DATEFORMAT dmy</code>.</p>
  
  <p>The problem is the same for ADO .NET as well as Entity framework. Setting the thread and ui culture to German also didn't help.</p>
  
  <p>It seems that C# SQL Connection sets the culture to default (English) independently of thread culture, date format or sql server language.</p>
  
  <p>Any ideas highly appreciated how to set the culture correctly - such that I don't need to send always <code>SET DATEFORMAT dmy</code> before the real sql text.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is my code to call the sql stored procedure and pass the dates using the c# sql parameter.</p>
  
  <pre><code>        SqlConnection sqlConnection = null;
          try
          {
              // open connection to the database
              sqlConnection = new SqlConnection(Convert.ToString(ConfigurationManager.ConnectionStrings[ProductivityAnalyzerDatabase.ConnectionStringName]));
              sqlConnection.Open();
  
              // setup command
              var sqlCommand = new SqlCommand("UpdateEmployeeBalances", sqlConnection);
              sqlCommand.CommandType = CommandType.StoredProcedure;
  
              sqlCommand.Parameters.Add(new SqlParameter("@employeeId", employeeId));
              sqlCommand.Parameters.Add(new SqlParameter("@startDate", startDate));
              sqlCommand.Parameters.Add(new SqlParameter("@endDate", endDate));
  
              sqlCommand.ExecuteNonQuery();
          }
          finally
          {
              if (sqlConnection != null &amp;&amp; sqlConnection.State == ConnectionState.Open)
              {
                  sqlConnection.Close();
              }
          }
  </code></pre>