简体   繁体   English

C# - 如何从 Sybase SQL Anywhere 11 检索数据?

[英]C# - How to retrieve data from Sybase SQL Anywhere 11?

Platform: visual Studio 2010
Language: C#
Framework: .NET 4.0
Project: Windows Form

So, I am unable to retrieve data yet I'm already connected.所以,我无法检索数据,但我已经连接上了。 I've also tried to connect by using 'Server Explorer' , and It could connect and retrieve data properly without any problem.我还尝试使用'Server Explorer'进行连接,它可以正常连接和检索数据,没有任何问题。

Settings on 'Server Explorer' “服务器资源管理器”上的设置

Connection String: Driver={SQL Anywhere 11};userid=*****;servername=*****;autostop=YES;integrated=NO;filedsn=C:\*****\*****.db.dsn;commlinks='SharedMemory,TCPIP{host=}';compress=NO

Provider: `.NET Framework Data Provider for ODBC`

Now, in my source code, I am using System.Data.Odbc;现在,在我的源代码中,我使用 System.Data.Odbc;

Code:

String connString = @"Driver={SQL Anywhere 11};userid=*****;servername=gamca;autostop=YES;integrated=NO;filedsn=C:\*****\*****.db.dsn;debug=NO;disablemultirowfetch=NO;commlinks='SharedMemory,TCPIP{host=}';compress=NO;password=*****";
OdbcConnection myConnection = new OdbcConnection(connString);
commandString = "DELETE from AGENCY";
try {
   using (OdbcCommand cmd = new OdbcCommand(commandString, myConnection)) {
   myConnection.Open();
   cmd.ExecuteNonQuery();
   myConnection.Close();
}

Error: Error [42S02] [Sybase][ODBC Driver][SQL Anywhere]Table 'AGENCY' not found错误: Error [42S02] [Sybase][ODBC Driver][SQL Anywhere]Table 'AGENCY' not found

I've also tried using OleDb and iAnywhere.Data.SQLAnywhere (V2), but no luck, I can't pass through this one error.我也尝试过使用 OleDb 和 iAnywhere.Data.SQLAnywhere (V2),但没有运气,我无法通过这个错误。

Anyone has experienced the same problem?任何人都遇到过同样的问题?

Any comment is appreciated, Thank you..任何意见表示赞赏,谢谢。。

This Query runs on Default database (eg Master) Add database name to your ConnString or CommandString as follow:此查询在默认数据库(例如 Master)上运行 将数据库名称添加到您的 ConnString 或 CommandString,如下所示:

commandString = "USE MyDatabase DELETE from AGENCY";

Dont forget to replace MyDatabase with your Database name.不要忘记用您的数据库名称替换 MyDatabase。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM