简体   繁体   English

对象_connection的方法打开失败

[英]Method open of object _connection failed

I am trying to connect to an SQL ce database within Excel. 我正在尝试连接到Excel中的SQL ce数据库。 It keeps giving me the: 它一直给我:

Method Open of object _connection failed

Error message whenever it gets to Conn.Open . 每当到达Conn.Open时出现错误消息。

I've never used ADO before so I'm not sure what's going wrong. 我以前从未使用过ADO,所以不知道出了什么问题。

Below is my connection script. 下面是我的连接脚本。

Sub SQLCeConnect()
Dim Conn As New ADODB.Connection
Dim Query As New ADODB.Command
Dim ConnStr As String
Dim RecordSet As New ADODB.RecordSet
Dim i As Integer

'the connection string
ConnStr = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=X:\ADOTEST\MYDB.sdf;"

'Open ADO Connection
Conn.ConnectionString = ConnStr
Conn.Open
Query.ActiveConnection = Conn
Query.CommandText = "SELECT * From DoorLayers"

Set RecordSet = Query.Execute
RecordSet.Close
Conn.Close
Conn.ConnectionString = ""

Do While Not RecordSet.EOF
    For i = 0 To RecordSet.Fields.Count - 1
        Debug.Print RecordSet.Fields(i).Name, RecordSet.Fields(i).Value
    Next
    RecordSet.MoveNext
Loop
RecordSet.Close

End Sub

The is usually a bad connection string, but yours looks fine. 通常是一个错误的连接字符串,但您看起来不错。 The next most common cause is that you don't have the OLEDB provider drivers on your desktop. 下一个最常见的原因是您的桌面上没有OLEDB提供程序驱动程序。 You can download it here 您可以在这里下载

http://www.microsoft.com/en-us/download/details.aspx?id=5821 http://www.microsoft.com/en-us/download/details.aspx?id=5821

Are you closing the connection before use it on WHILE . WHILE上使用连接之前,是否要关闭连接? You must close it after use the while instruction. 您必须使用while指令后将其关闭。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对象“工作簿”的方法“打开”失败 - Method 'Open' of object 'Workbooks' failed 运行时错误“-2147417848 (80010108)”:对象“_Recordset”的“打开”方法失败 - 使用 Excel 和 ADO 连接 - Run-time error '-2147417848 (80010108)': Method 'Open' of object' _Recordset' failed - using Excel with ADO Connection 对象工作簿的方法打开失败错误 - Method open of object workbooks failed error 运行时错误“1004”-对象“工作簿”的方法“打开”失败 - Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed 运行时错误“ 1004”:对象“工作簿”的方法“打开”失败 - Run-time error'1004': Method 'Open' of object 'Workbooks' failed Excel错误代码1004 - 对象工作簿的方法打开失败 - Excel error code 1004 - method open of object workbooks failed Excel打开只读工作簿时,对象“工作簿”的方法“打开”失败 - excel Method 'open' of object 'workbooks' failed error when opening a read only workbook 有时在子目录中访问打开的工作簿会生成错误1004“对象'_Global'的'Sheets'的方法未失败” - Accessing open workbook in a sub generates Error 1004 “Method of 'Sheets' of Object '_Global' not failed” sometimes 从Powershell启动时,VBA中的“对象'工作簿'的方法'打开'失败”,但直接从Excel调用时有效 - “Method 'Open' of object 'Workbooks' failed” in VBA when launched from a Powershell, but work when directly call from Excel Microsoft Access 例程生成的 Excel 报告出现错误 1004:方法打开对象工作簿失败 - Excel Reports generated by Microsoft Access routine gets Error 1004: Method Open Object Workbooks Failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM