【问题标题】:SQL Anywhere Error -157: Cannot convert '08/10/09' to a timestampSQL Anywhere 错误 -157:无法将“08/10/09”转换为时间戳
【发布时间】:2017-11-02 20:28:52
【问题描述】:

这里也有人问过同样的问题:Getting Exception 'Cannot convert '08/10/09' to a timestamp' while connecting to Sybase Database with .Net

没有提供答案,我无法将 cmets 发布到该线程,因为我是新用户,所以我试图再次询问。

我正在尝试构建一个 .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 年 8 月 10 日的日期不是我在任何地方提交的日期。另请注意,此异常发生在 AseConnection.Open() 上,我没有提交格式错误的日期,数据库中也不存在格式错误的日期。

【问题讨论】:

  • 所以我想通了,但无法发布答案:(请投票我的问题,以便我发布答案。
  • 回到这一点,很想发布一个更详细的答案,但首先需要一些支持。问题是驱动程序本身有一个错误。您可以使用通用 ODBC 驱动程序/连接器进行连接,不会出现此问题。

标签: c# database ado.net sybase sqlanywhere


【解决方案1】:

您似乎尝试将日期 (MMDDYYYY) 数据类型应用于 DateTime 或 Time 数据类型。这些本质上是不同的数据类型,包含不同的信息。

时间:

  • 小时 (hh)
  • 分钟(毫米)
  • 秒 (ss)

日期:

  • 月(MM)
  • 天(DD)
  • 年份 (YYYY)

【讨论】:

  • 我不明白,因为它实际上是两行代码。使用连接字符串创建连接对象并调用 connect 方法。幕后有什么东西会自动尝试提交某种日期吗?
猜你喜欢
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
  • 2016-10-16
  • 1970-01-01
  • 2017-01-26
  • 2020-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多