未指定错误:打开OleDbConnection时

时间:2012-04-19 05:47:15

标签: ms-access office-2010 oledbconnection

  • 使用Office 2010在Windows XP上出现未指定的错误。
  • 问题可以在某些机器上重现,而不是全部。

代码

  Dim dbConn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\test\data.mdb")
   try
   {
   dbConn.Open() 
   }

异常

Exception:   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString   constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions    options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at    System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection    owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()

1 个答案:

答案 0 :(得分:-2)

试试这个

Dim dbConn As  OLEDBConnection
Set dbConn = New Connection
dbConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\test\data.mdb;"

您需要声明dcConn,然后在单独的语句中设置它。