title: ODBC Connection Issues: Function Sequence error when executing anything
body: <p>I've been tasked with a one time migration from a 4D database to our MSSQL structure. I've got a datasource set up in the ODBC administrator and I was able to connect to it without issues. </p>
  
  <p>I 'reverse engineered' the schema in Visio so I can get a good visual of the relationships between the tables and plan out how I'm going to re-structure the 4D data to fit into our schema. I created a simple console application as this will be a one time run, and I'm able to make the connection to the data source, but as soon as I execute anything, the connection drops or is disabled. </p>
  
  <pre><code>  System.Data.Odbc.OdbcConnection conn = 
                 new System.Data.Odbc.OdbcConnection("Dsn=4D v12 datasource");
          try
          {
              conn.Open();
              Console.WriteLine("Status of Connection:" + conn.State.ToString());
              //Here it says the connection to the DB is open and ready for action
              Console.ReadLine(); 
              //pause to visually confirm  the connection is open
              OdbcCommand com = new OdbcCommand("SELECT * FROM ATable", conn);
              com.CommandType = CommandType.Text;
              Console.Write(com.ExecuteNonQuery());
              //Right here it blows up and closes the connection                
           }
  </code></pre>
  
  <p>I also tried to do something with data set and data adapter, but to no avail. </p>
  
  <pre><code>System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection("Dsn=4D v12 datasource");
          try
          {
              conn.Open();
              Console.WriteLine("Status of Connection:" + conn.State.ToString());                
              Console.ReadLine();
              OdbcCommand com = new OdbcCommand("SELECT * FROM ATable", conn);
              com.CommandType = CommandType.Text;
              //Also tried using data sets and data adapters
              DataSet dsTest = new DataSet();
              OdbcDataAdapter dataAdapter = new OdbcDataAdapter(com);
              //but right at this line the connection suddenly disconnects
              dataAdapter.Fill(dsTest);
  
          }
          catch (Exception e)
          {
              Console.WriteLine("Failure:" + e.Message.ToString());
              // the exception message reads simply connection has been disabled. 
              Console.WriteLine("Status of Connection: " + conn.State.ToString());
              Console.ReadLine();
          }
          finally 
          {
              Console.Write("Closing connection.");
              conn.Close();
              Console.Write(".");
              conn.Dispose();
              Console.WriteLine(".");
              Console.WriteLine("Connection Closed and Disposed");
              Console.ReadLine();
          }
  </code></pre>
  
  <p>I've tried to look for anyone experiencing this same difficulty, but the documentation I've found has been scarce and not very helpful in this specific regard. There is a good amount of information about executing queries on the 4D product, but not from across the digital divide. Anyone with experience please advise. Thanks for your time and for any help you may be able to give, avid reader.</p>