我有一个关于从显然是 Transoft 驱动程序的 DSN 中连接和获取表名的问题。这个问题在这里:
OdbcConnection.GetSchema("TABLES"); 不工作
在那个有效的答案之后,我可以显示所有表名。现在我发现,阅读这些表格仍然无法正常工作。我收到一个错误:
Failed to connect to data source: ERROR [HY000][Transoft][TSODBC][usqlsd](log: 5852-142748) File does not exist: APPT
其中 APPT 是它读取的表名。现在是一段简单的代码:
void dumbRead(String tableName)
{
OdbcCommand sqlCommand = conn.CreateCommand();
// execute sql
sqlCommand.CommandText =
"select * from " + tableName; //I even tried with qualifying table name like:
// "select * from douglas." + tableName; where the douglas. is the account i.e.
// the table owner I think.
OdbcDataReader sqlReader = sqlCommand.ExecuteReader();
int fieldCount = sqlReader.FieldCount;
MessageBox.Show("Field Count: " + fieldCount);
}
但由于某种原因它不喜欢我的 select * 语句,所以它不起作用。它只是给出了上述错误。Transoft USQL 真的是与众不同的野兽吗?
到目前为止,其他一切(再次感谢我得到答案的上一篇文章)都运行良好。
根据评论,这是我的连接字符串:
private void Form1_Load(object sender, EventArgs e)
{
txtDSNName.Text = "Company_Shared";
}
private void btnConnect_Click(object sender, EventArgs e)
{
ConnectToData(txtDSNName.Text);
}
public void ConnectToData(String dsn)
{
conn= new System.Data.Odbc.OdbcConnection();
//conn.ConnectionString = "FIL=MS Access;DSN=" + dsn;
conn.ConnectionString = "DSN=" + dsn; //dsn equals "Company_Shared"
try
{
conn.Open();
MessageBox.Show("Connected!");