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

问题描述 投票:0回答:1
Platform: visual Studio 2010
Language: C#
Framework: .NET 4.0
Project: Windows Form

所以,我无法检索数据,但我已经连接了。我还尝试使用“服务器资源管理器”进行连接,它可以正常连接和检索数据,没有任何问题。

'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`

现在,在我的源代码中,我使用的是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 [42S02] [Sybase][ODBC Driver][SQL Anywhere]Table 'AGENCY' not found

我也尝试过使用OleDb和iAnywhere.Data.SQLAnywhere(V2),但没有运气,我无法通过这一个错误。

任何人都遇到过同样的问题?

任何评论表示赞赏,谢谢..

c# sqlanywhere
1个回答
0
投票

此查询在默认数据库(例如Master)上运行。将数据库名称添加到ConnString或CommandString,如下所示:

commandString = "USE MyDatabase DELETE from AGENCY";

别忘了用数据库名称替换MyDatabase。

© www.soinside.com 2019 - 2024. All rights reserved.