Home > Software engineering >  VS2013 ADO open Excel file connection is always wrong...
VS2013 ADO open Excel file connection is always wrong...

Time:10-02

I'm VS2013 platform using ADO to Excel file, for the first time to do it, m_pConnection connection error problem, there is no hire, to consult the great spirit is what is going on??????? The machine has been installed excel, also upgrade AccessDatabaseEngine_X64. Exe engine, I am win764bit operating system,
My main operating steps are as follows:
1, in stdafx. H of lead into the ADO in
 # import "C: \ Program Files \ Common Files \ System \ ado \ msado15 DLL" no_namespace rename (" EOF ", "ADOEOF") rename (" BOF, "" ADOBOF") 

2, the initialization:
 if (! AfxOleInit ())//this is to initialize the COM libraries 
{
AfxMessageBox (_T (" OLE initialization error!" ));
Return FALSE;
}

3, m_pConnection instance attachment Excel:
 _bstr_t bstrConn="Provider=Microsoft. ACE. The OLEDB. 12.0. Data Source=D: \ \ test2 XLSX; Extended Properties=12.0 Xml Excel; HDR=No. IMEX=1 "; 
Try {
Retrieves the hr;
Hr=m_pConnection. CreateInstance (" ADODB. Connection ");
If (SUCCEEDED (hr))
{
//m_pConnection - & gt; PutCursorLocation (adUseClient);
M_pConnection - & gt; CommandTimeout=0;
M_pConnection - & gt; Open (bstrConn, ""," ", adModeUnknown);
}
}
Catch _com_error (e)
{

Cstrings errormessage;
Errormessage. The Format (_T (" open the Excel failed! \ r \ n error message: % s "), e.E rrorMessage ());
AfxMessageBox (errormessage);
}


Run this code suggests the following error:

When changing the connection string to:
 _bstr_t bstrConn="Provider=Microsoft. ACE. The OLEDB. 12.0. Data Source=D: \ \ test2 XLSX; Extended Properties='Excel Xml 12.0; HDR=No. IMEX=1; '"; 

Note: changes are in the Extended Propertiec=behind with single quotes, and added a semicolon after the IMEX=1, because I checked some tutorial is so of the writing, also has the kind of writing the above, but still there is an error, you will be prompted:

If you remove the semicolon after IMEX=1, will appear in front of the errors, if the Extended Properties after=add double quotation marks, also appeared in front of that kind of mistake, anyway I tried multiple online tutorial will appear this two kinds of errors, I really didn't recruit, asked the great spirit, this problem is out in where? Thank you,,,
Data Source=D: \ \ this path double slash, single slash, against all tried, also not line,,,

CodePudding user response:

http://blog.csdn.net/fhfanxin/article/details/50805920

CodePudding user response:

Or not,,,

CodePudding user response:

Error estimation is the connection string, can use ADO assistants under test,

CodePudding user response:

Ok, I try find ADO assistant

CodePudding user response:

The
reference 3 floor zyq5945 response:
error estimation is the connection string, can use ADO assistant under test,

Or not, there is an error, I change the ADO assistant Data Source in the path to my Excel file path, keep assistant other string, such mistakes:

Where is the eldest brother this is wrong?

CodePudding user response:

You are the corresponding office version machine?
Or AccessDatabaseEngine_X64. Exe to 32-bit try,

CodePudding user response:

In a 64 - bit Windows:
64 exe and DLL in the directory c: \ Windows \ sys tem32 directory.
32 bit exe and DLL in the directory c: \ Windows \ sys wow64 directory.
So pay attention to:
In win64 system registered under 32-bit ocx DLL to 32 ocx or copy the DLL to the c: \ Windows \ syswow64 \ directory,
And registered to c: \ Windows \ syswow64 \ regsvr32 XXXXXXX ocx or DLL
Under win64 a system set up 32-bit programs use a database alias to c: \ Windows \ \ syswow64 \ cliconfg exe
Under win64 a system set up a 32-bit application system DSN to c: \ Windows \ \ syswow64 \ odbcad32 exe
A 64 - bit Windows platform attention point of the file system redirection http://www.cnblogs.com/jiake/p/4981555.html
64 - bit Windows platforms attention point of the registry to redirect http://www.cnblogs.com/jiake/p/4956218.html

CodePudding user response:

The
reference 7 floor zhao4zhong1 response:
under the 64 - bit Windows:
64 exe and DLL in the directory c: \ Windows \ sys tem32 directory.
32 bit exe and DLL in the directory c: \ Windows \ sys wow64 directory.
So pay attention to:
In win64 system registered under 32-bit ocx DLL to 32 ocx or copy the DLL to the c: \ Windows \ syswow64 \ directory,
And registered to c: \ Windows \ syswow64 \ regsvr32 XXXXXXX ocx or DLL
Under win64 a system set up 32-bit programs use a database alias to c: \ Windows \ \ syswow64 \ cliconfg exe
Under win64 a system set up a 32-bit application system DSN to c: \ Windows \ \ syswow64 \ odbcad32 exe
A 64 - bit Windows platform attention point of the file system redirection http://www.cnblogs.com/jiake/p/4981555.html
64 - bit Windows platforms attention point of the registry to redirect http://www.cnblogs.com/jiake/p/4956218.html

Thank you, I have a try.

CodePudding user response:

refer to 6th floor zyq5945 response:
you machine the corresponding office version?
Or AccessDatabaseEngine_X64. Exe to 32-bit try


My system is a 64 - bit Windows 7, office2010 has been installed, AccessDatabaseEngine_X64. Exe this also installed, but still appear the same mistake,

CodePudding user response:

Look at in this way can not,
  • Related