我的任务是一次性从 4D 数据库迁移到我们的 MSSQL 结构。我在 ODBC 管理员中设置了一个数据源,并且能够毫无问题地连接到它。
我在 Visio 中对架构进行了“逆向工程”,因此我可以清楚地了解表之间的关系,并计划如何重新构造 4D 数据以适应我们的架构。我创建了一个简单的控制台应用程序,因为这将是一次性运行的,并且我能够连接到数据源,但是一旦我执行任何操作,连接就会断开或被禁用。
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
}
我也尝试过对数据集和数据适配器做一些事情,但无济于事。
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();
}
我试图寻找任何遇到同样困难的人,但我发现的文档很少,而且在这方面的帮助不大。有大量关于在 4D 产品上执行查询的信息,但不是来自数字鸿沟。有经验的请指教。热心读者,感谢您抽出宝贵时间提供帮助。
最佳答案
显然问题的根本原因在于驱动程序。将我从网站上获得的驱动程序替换为所有者发送的驱动程序后,连接不再被禁用,一切都按预期工作。
关于c# - ODBC 连接问题 : Function Sequence error when executing anything,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16043018/