2017-06-01 140 views
1

這個同樣的問題已經在這裏問:Getting Exception 'Cannot convert '08/10/09' to a timestamp' while connecting to Sybase Database with .NetSQL Anywhere錯誤-157:無法轉換'08/10/09' 的時間戳

沒有回答已經提供了,我無法發表評論,該線程作爲我是一個新用戶,所以我試圖再次問。

我試圖建立一個.NET應用程序來談論到Sybase/ASE/SQL Anywhere數據庫,使用SAP在這裏找到的信息:http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.sdk_12.5.1.adonet/html/adonet/Connecting_adodotnet_development.htm

隨着所有的說,這裏是我使用的代碼:

private void MainWindow_Load(object sender, EventArgs e) { 
     using (AseConnection con = new AseConnection("Provider=ASEOLEDB.1; Data Source=localhost; Port=2638; Database={correct db name}; Uid={correct username}; Pwd={correct password}; Charset=iso_1;")) { 
      con.Open(); 
     } 
    } 

我得到扔在con.Open()異常:

「SQL Anywhere錯誤-157:無法轉換'08/10/09' 的時間戳」

堆棧跟蹤如下:

at Sybase.Data.AseClient1.AseConnection.Open() 
    at Sybase.Data.AseClient.AseConnection.Open() 
    at ReportGenerator.MainWindow.MainWindow_Load(Object sender, EventArgs e) 
    in C:\Projects\DiCello\ReportGenerator\ReportGenerator\MainWindow.cs:line 21 
    at System.Windows.Forms.Form.OnLoad(EventArgs e) 
    at System.Windows.Forms.Form.OnCreateControl() 
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 
    at System.Windows.Forms.Control.CreateControl() 
    at System.Windows.Forms.Control.WmShowWindow(Message& m) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
    at System.Windows.Forms.Form.WmShowWindow(Message& m) 
    at System.Windows.Forms.Form.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

我已經看到了以下內容:https://archive.sap.com/discussions/thread/3646147,然而這並不適用,因爲我不是試圖運行一個查詢,我還不能建立到運行建議的查詢的連接。 2009年10月8日的日期不是我提交到任何地方的日期。還要注意,這個異常是在AseConnection.Open()上的,我沒有提交格式錯誤的日期,格式錯誤的日期也不存在於數據庫中。

+0

所以我想通了,但不能發佈的答案:(請投了我的問題,所以我可以張貼的答案。 –

回答

0

看來你嘗試應用日期(MMDDYYYY)數據類型到DateTime或Time數據類型。這些實質上是不同的數據類型,包含不同的信息。

時間:

  • 小時(HH)
  • 分鐘(mm)
  • 秒(SS)

日期:

  • 月(MM)
  • 天(DD)
  • 年(YYYY)
+0

我不明白,因爲它實際上是兩行代碼。使用連接字符串創建連接對象並調用connect方法。是否有幕後的內容會自動嘗試提交某種日期? –