VB6 ADODB 因 SQL Compact 失败:多步操作生成错误

发布于 2024-08-21 12:15:29 字数 1331 浏览 6 评论 0原文

我正在转换一个旧的应用程序以使用 SQL Compact 数据库(它可以与 SQ Server 2005 和 2008 一起使用),并且在尝试执行简单的选择命令时使用以下代码会出现错误:

Private Const mSqlProvider          As String = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"
Private Const mSqlHost              As String = "Data Source=C:\database.sdf;"
Private mCmd                        As ADODB.Command   ' For executing SQL'
Private mDbConnection               As ADODB.Connection


Private Sub Command1_Click()
   
    Dim DbConnectionString As String

    DbConnectionString = mSqlProvider & _
                            mSqlHost

        
    Set mDbConnection = New ADODB.Connection
    mDbConnection.CursorLocation = adUseClient
    
    Call mDbConnection.Open(DbConnectionString)
    
    If mDbConnection.State = adStateOpen Then
        Debug.Print (" Database is open")
        ' Initialise the command object'
        Set mCmd = New ADODB.Command
        mCmd.ActiveConnection = mDbConnection
        
    End If
    

    mCmd.CommandText = "select * from myTable"
    mCmd.CommandType = adCmdText
    mCmd.Execute  ' FAILS HERE! '

    
End Sub

我在中引用了 Microsoft ActiveX Data Access Object 6.0 Library该项目。

我得到的错误是:

运行时错误 -2147217887 (80040e21)

多步操作生成错误。检查每个状态值

只是想知道是否有人有任何建议?

谢谢

I am converting an old application to use SQL Compact database (it works ok with SQ Server 2005 and 2008) and using the following code gives an error when attempting to execute a simple select command:

Private Const mSqlProvider          As String = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"
Private Const mSqlHost              As String = "Data Source=C:\database.sdf;"
Private mCmd                        As ADODB.Command   ' For executing SQL'
Private mDbConnection               As ADODB.Connection


Private Sub Command1_Click()
   
    Dim DbConnectionString As String

    DbConnectionString = mSqlProvider & _
                            mSqlHost

        
    Set mDbConnection = New ADODB.Connection
    mDbConnection.CursorLocation = adUseClient
    
    Call mDbConnection.Open(DbConnectionString)
    
    If mDbConnection.State = adStateOpen Then
        Debug.Print (" Database is open")
        ' Initialise the command object'
        Set mCmd = New ADODB.Command
        mCmd.ActiveConnection = mDbConnection
        
    End If
    

    mCmd.CommandText = "select * from myTable"
    mCmd.CommandType = adCmdText
    mCmd.Execute  ' FAILS HERE! '

    
End Sub

I have referenced Microsoft ActiveX Data Access Object 6.0 Library in the project.

The error I get is:

Run-Time error -2147217887 (80040e21)

Multipe-Step operation generated errors. Check each status value

Just wondering if anyone has any suggestions?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

默嘫て 2024-08-28 12:15:29

现在可以正常工作了:

更改

mDbConnection.CursorLocation = adUseClient 

mDbConnection.CursorLocation = adUseServer worked!  

Got this working now:

Changing

mDbConnection.CursorLocation = adUseClient 

to

mDbConnection.CursorLocation = adUseServer worked!  
小草泠泠 2024-08-28 12:15:29

我不能 100% 确定错误是来自此代码而不是其后的内容,这是“最后已知的正确”类型位置。错误的最常见原因:

  1. 您正在将数据隐式转换为错误的数据类型(例如,正在将字母字符串值插入到数字字段中。)

  2. 您插入的值格式错误(往往发生在日期上)

  3. 正在将空值插入到不允许空值的字段中。

  4. 您的值超出了字段的最大长度。 (例如,在 10 个字符的字段中粘贴 50 个字符长的字符串)

此外,如果连接未打开,则不会捕获错误。

I'm not 100% sure the error is from this code rather than something after it and this is the "last known good" type position. Most common causes of the error:

  1. You are implicitly converting data into the wrong datatype (e.g. An alpha string value is being inserted into a numeric field. )

  2. You are inserting a value with a wrong format (tends to happen on dates most frequently)

  3. A null value is being inserted into a field that does not allow nulls.

  4. You have exceeded the max length of the field with a value. (e.g. sticking a string 50 characters long in a 10 character field)

Also, there is nothing catching an error if the connection is not open.

盗琴音 2024-08-28 12:15:29

这个问题与这两个问题非常相似:

这将是以下三件事之一:

  • 连接字符串(您使用什么驱动程序?)
  • 安全性(使用集成安全性而不是用户名/密码)
  • 或正如贝利兹所说,光标位置

This question is very similar to these two:

It will be one of three things:

  • The connection string (what driver are you using?)
  • Security (using Integrated Security instead of a username/password)
  • or as Belliez said, the Cursor Location
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文