VB6 ADODB 因 SQL Compact 失败:多步操作生成错误
我正在转换一个旧的应用程序以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在可以正常工作了:
更改
为
Got this working now:
Changing
to
我不能 100% 确定错误是来自此代码而不是其后的内容,这是“最后已知的正确”类型位置。错误的最常见原因:
您正在将数据隐式转换为错误的数据类型(例如,正在将字母字符串值插入到数字字段中。)
您插入的值格式错误(往往发生在日期上)
正在将空值插入到不允许空值的字段中。
您的值超出了字段的最大长度。 (例如,在 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:
You are implicitly converting data into the wrong datatype (e.g. An alpha string value is being inserted into a numeric field. )
You are inserting a value with a wrong format (tends to happen on dates most frequently)
A null value is being inserted into a field that does not allow nulls.
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.
这个问题与这两个问题非常相似:
这将是以下三件事之一:
This question is very similar to these two:
It will be one of three things: