Pregunta

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.

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.

  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                
         }

I also tried to do something with data set and data adapter, but to no avail.

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();
        }

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.

¿Fue útil?

Solución

Apparently the root cause of the issue was in the driver. Upon replacing the driver I got from the website with one sent from the proprietor, the connections ceased being disabled and all is working as intended.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top