2012-10-03 39 views
0
Platform: visual Studio 2010 
Language: C# 
Framework: .NET 4.0 
Project: Windows Form 

所以,我無法檢索數據,但我已經連接。 我也嘗試使用'服務器資源管理器'進行連接,它可以正常連接和檢索數據,沒有任何問題。C# - 如何從Sybase SQL Anywhere 11中檢索數據?

設置在 '服務器資源管理器' 現在

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),但沒有運氣也試過,我不能穿過這一個錯誤。

任何人都遇到過同樣的問題?

任何評論表示讚賞,謝謝。

回答

0

此查詢的默認數據庫(例如法師) 您CONNSTRING或CommandString中添加數據庫名稱如下運行:

commandString = "USE MyDatabase DELETE from AGENCY"; 

不要忘記更換MyDatabase與您的數據庫名稱。

+0

我在我的connString中添加了「dsn = MyDatabase」,但仍然出現同樣的錯誤。我也嘗試了「從AGENCY中使用MyDatabase DELETE」到我的commandString中,並且它產生了新的錯誤,說「DELETE行1附近的語法錯誤」 – choz

相關問題