Cant get around an OLE DB error - excel

I am currently getting the following error:
Microsoft OLE DB Service Components error '80040e73'
Format of the initialization string does not conform to the OLE DB specification.
My code is as follows with the variable ExportPath being created on the fly to create unique XLS names. e.g. D:\RiskCheck\Website\demo\newsite\exports\Reporting_Export_NTQ0KZZU0T262014115941.xls
set cnn=Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source="&ExportPath&";" & _
"Extended Properties='Excel 8.0;HDR=YES;';"
This issue has been driving me absolutely mental all morning and numerous fixes found across Google haven't been successful, any advice rather welcome!

Related

MICROSOFT ODBC - ADO string portability (VBA) on Windows 10_64 bits , Excel_64 bits , ODBC_64 bits

I have been asked to check at an issue on an "old" excel file, that have been moved to a new server and which is "no more working".
Before I was granted to access on the new server, I have tested on my laptop (Win10/office 64/oracle client 64/ODBC 64).
The VBA connection string is :
strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
strConOracle = strConOracle & "(HOST=" & HOST & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & DATABASE
strConOracle = strConOracle & "))); uid=" & USER & " ;pwd=" & PASSWORD & ";"
Set oConOracle = CreateObject("ADODB.Connection")
Set oRsOracle = CreateObject("ADODB.RecordSet")
After several tests, I think , I have understood that the string "{Microsoft ODBC for Oracle}" refers to an ODBC 32bits pilot. In my 64bits ODBC, the name is "Oracle in OraClient19Home1".
If I just change {Microsoft ODBC for Oracle} by {Oracle in OraClient19Home1} , it's not working (too quick to win :) )
So I'm just wondering If you know if ADODB connection is still possible on a 64 bits ?
And if there's some tricky thing we got to add in the VBA code.
Yes, I know there's a feature in excel called "getdata" that use external ODBC DSN connection, but it's too invasive. It needs to rework all the mechanism of the VBA code, and it's too long.
So I first want to check at VBA ADO connections.
Just for information , when I finally get in the issuing server (Windows ServerĀ® 2008 Standard/Office 32bits/Oracle 32bits/ODBC 32bits). I just need to add some trusted locations and buttons in FORM mode to get it work back again. I guess that's because in the ODBC 32bits, there is a pilot called "Microsoft ODBC for Oracle" or because there's a registry keys at this name :
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\Microsoft ODBC for Oracle]
But I feel that, one day we won't be able to work in 32bits.
And it's may be a good warning for upgrading to 64bits.
regards
G

How to connect Oracle Database using 64-bit Excel in Windows 10

I'm trying to connect my Excel to Oracle with this connection string in VBA:
And I get error msg below:
Run-time error '-2147467259 (800004005)':
ORA-12154: TNS:could not resolve the connect identifier specified
Using:
- Excel 2016 64-bit
- Windows 10 64 bit
- Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
- PL/SQL Release 12.1.0.2.0
- CORE 12.1.0.2.0
- TNS for Linux: Version 12.1.0.2.0
- NLSRTL Version 12.1.0.2.0
Excel 64-bit & oracle is provided by company, hope can settle it without change excel to 32-bit. Any help will be appreciated. I actually already tried to settle it for two days and see no hope at all. Thanks for your time.
Not sure if is the driver i used is 32-bit?
Microsoft ODBC for Oracle, MSORCL32.DLL
Oracle in Client_11_Std_x86_1, SQORA32.DLL
Dim cnPubs As ADODB.connection
Set cnPubs = New ADODB.connection
Dim strConn As String
With cnPubs
strConn = "Provider=OraOLEDB.Oracle;" & _
"Data Source=" & sSource & ";" & _
"User ID=" & sAC & ";Password=" & sPW & ";"
.Open strConn
.CommandTimeout = 0
End With
Looks like you missed some basics, let's explain. When you want to connect to an Oracle database, no matter whether sqlplus or VBA or anything else then actually you would have to do it like this:
sqlplus MyUserName#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))
However, nobody is willing or able to remember such a long and complex database name.
So, you would prefer to use an alias, i.e. a shortcut for (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))
There are different methods to define and resolve such aliases (see Managing Network Address Information), the most common and easiest way is to use a local tnsnames.ora file.
In your tnsnames.ora file you can add a line like this:
MY_DB=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))
Then you can connect to your database simply with
sqlplus MyUserName#MY_DB
Now the next question is: How does my application find the tnsnames.ora file on my system? The answer is not as trivial as you might assume, see Determining location of relevant tnsnames.ora file
The most secure solution is: Define an environment variable TNS_ADMIN and put as value the directory name where your tnsnames.ora file is located.
Provider "msdaora" uses a different pattern to find the tnsnames.ora file than "Oracle OLE DB" provider does. msdaora finds your file, Oracle OLE DB does not. Settings an environment variables TNS_ADMIN makes it working for both.

"Unspecified error" while opening an ADODB connection

I am facing "Unspecified error" in only one PC of my users.
Run-time error '-2147467259 (80004005)':
Unspecified error
I am running the below VBA code to open a connection to Access database located in network shared drive. But the code throws the error whenever it is trying to run the .Open statement.
I thought it is a driver issue and installed Access 2007 Database engine in the user's PC and replaced Provider with "Microsoft.ACE.OLEDB.12.0" but it doesn't work.
Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim retVal As Boolean
Dim strSQL As String
retVal = False
On Error GoTo CatchError
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = Initialize.GetDBPwd 'returns pass
.Open Initialize.GetDbConnectionString 'returns the network DB path
End With
I have the same issue while making an ADODB connection from a local Excel file to another local Excel file.
The only way how I solve it is re-opening the main Excel file from which I do the connection. Nothing else done, and the function works again.
My connection function:
Sub SetConReadOnly(ByRef con1 As Object, ByRef rst1 As Object, sFile As String)
If con1 Is Nothing Then Set con1 = CreateObject("ADODB.Connection")
If rst1 Is Nothing Then Set rst1 = CreateObject("ADODB.Recordset")
con1.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & sFile & ";" & _
"Extended Properties=""Excel 12.0;HDR=No;IMEX=1;"""
End Sub
(I use Office 2013 32-bit, Windows 7 64-bit)
What is the version of your Excel?
I had that error, and the solution was changing the provider. Try changing to this:
On Error GoTo CatchError
Set cn = New ADODB.Connection
With cn
.provider = "Microsoft.Mashup.OleDb.1"
.Properties("Jet OLEDB:Database Password") = Initialize.GetDBPwd 'returns pass
.Open Initialize.GetDbConnectionString 'returns the network DB path
End With
Still haven't found any solution to this issue but it seem the issue is limited to only one user.
I wrote some test macros, in the same file which has the original macros, that open DB connection to local DB file and remote DB file. The test is successful but for some reason that one particular macro still throws that "Unspecified Error" in that specific users machine.
We concluded it is most likely due to a office got corrupted. We will repair the office and hopefully that should fix the issue. Will let you know if this works.
Thanks.
I have faced this issue and identified that this issue is specific to a Win7 64 Bit with a 32 Bit Office Installation. The solution I accidentally came across was that If I saved the file manually and rerun the code, it worked seamlessly post that. On trying to incorporate a save in the error handler and calling in the main function again did not work. However saving the file through Application.SendKeys "^s" and then running the file through another thread could replicate the outcome of the manual save.
On further investigation, I identified that the error was because of certain columns in the source being added at run-time before the query and it seems the sql engine queries from a different internal raw source which is not updated with the changes unless the save happens and that was the reason for error.
I got this error while using same variables in two different modules. It went away when I changed the variable names. It is strange but it worked!! Hope that solves your problem. Thanks

OleDb connection to excel file at sharepoint doesn't work

I have in my VBA code connection string pointing to the workbook itself, e.g.:
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Persist Security Info=False;" & _
"Extended Properties=""Excel 12.0 Macro;HDR=Yes"
It works well when the file is stored at local, but after it's uploaded to a Sharepoint space, it no longer works due to connection failure ("Connection could not be established!").
Any idea to get it working? Thanks in advance!
Not much detail here which leaves a lot of assumptions to be made...but here goes...
A bit of googling shows that there are lots of Microsoft.ACE.OLEDB errors with Access; you make not mention of Access so, that could be your issue right there - wrong connection type.
Since your connection is "to the workbook itself" the easy solution is to refernce the cells via a simple XL function.
In our environment, (Office 2007, SP 2007) it is worth noting that connections typically contain a connection string: "Provider=Microsoft.Office.List.OLEDB.2.0"). Again, probably the wrong connection string.
Try storing the spreadsheet in SP first, open the file (checked out of course), then create the connection.
If all else fails, I like the "record macro then fix the code" method!

loading csv "Could not find installable ISAM"

Im building a program in Excel VBA to automate a process and I require data stored in a csv file to be imported. So, I'm trying to use a query table to import specific columns in a csv file.
Im using ADO to interface with the csv file using the Jet Provider OLE DB. In the connection string I have specified the provider, data source, and extended properties. Im using windows xp and office 2003, so my Excel version is 8.0. I specified the provider as Microsoft.Jet.OLEDB.4.0. My code is pasted below. When the code executes I get the error "Could not find installable ISAM" at the last line that I included in the below code. I cant find anything wrong with the syntax so I was wondering if this error could be because I dont have the correct version of Jet installed? Please see code below. Thanks
Sub Excel_QueryTable()
Dim oCn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim ConnString As String
Dim SQL As String
Dim qt As QueryTable
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\testfile.csv;" & _
"Extended Properties=Excel 8.0;HDR=Yes; FMT=Delimited; IMEX=1"","
Set oCn = New ADODB.Connection
oCn.ConnectionString = ConnString
oCn.Open
Try this:
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\directory\where\csv\file\is\;" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited"""
I don't think you want to use the "Excel 8.0" portion, but you aren't actually connecting to an Excel worksheet; you're connecting to a text file. Also, you had extra spaces, and connection strings are REALLY picky about those, so I've deleted them.
Note that you can set the delimiter here:
HKLM\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\Format
Mine is currently CSVDelimited; other options are TabDelimited and Delimited(;)
I found this info at: http://www.connectionstrings.com/textfile
-- EDIT --
Instead of pointing to a specific .csv file, you actually point the data source to a target directory. Note my changes above, in the connection string: the filename has been removed, and the path now ends in a \.
In order to use this type of data source, you actually need to teach the driver how the file is laid out. You do this through the use of a schema.ini file.
You can create the .ini file one of two ways:
Manually edit the file by hand, in notepad, using the above link to provide usage.
Use the tool built into the ODBC Data Source Admin.
In order to use the tool, you need to actually go through the steps of creating a data source. You don't actually need the data source, but as far as I can tell, it's the only way to get to the create schema.ini creation tool.
To get there:
Go to the ODBC control panel.
Add a new DSN, type: Microsoft Text Driver (*.txt, *.csv), click Finish
On "ODBC Text Setup", uncheck Use Current Directory and select the directory where your file lives.
Click on the options button, and click on the Define Format button.
Click on the file that you want to work with, and click "Guess" to get you started, then refine the data types as necessary.
When done, click OK, and you should see a schema.ini file in the directory where your .csv file is. Open it in notepad, and make sure it looks right.
The above connection string should now work correctly, using ONLY the directory where your csv lives, not the full path to the .csv.

Resources