I have been able to successfully connect my excel to MS access, and using the connection, I am able to push and pull data to and from excel to Access DB. However, I noticed, if my connection string has space in between like mentioned below, I am unable to establish the connection. Is there any way around it?
Connection string with space
Set oADODBCon = New ADODB.Connection
oADODBCon.Open Microsoft.ACE.OLEDB.12.0;Data Source=\\XYZ-123\0123\ABC 2020 Test Operations\MyDb.accdb;Persist Security Info=False;
I have tried using single quotes in my connection string as below but it still didn't work
Set oADODBCon = New ADODB.Connection
oADODBCon.Open Microsoft.ACE.OLEDB.12.0;Data Source='\\XYZ-123\0123\ABC 2020 Test Operations\MyDb.accdb';Persist Security Info=False;
Any help would be much appreciated!
oADODBCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\XYZ-123\0123\ABC 2020 Test Operations\MyDb.accdb;Persist Security Info=False;"
Related
Connecting to Cloud SQL appears to be different than connecting to normal MySQL databases.
I have added the 'Instance connection name' after the 'Public IP address'.
I am getting an error:
'Unknown MySQL server host'
Dim Cnn As Object
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open ("DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=xxx.xxx.xxx.xxx\instanceConnectionName;DATABASE=databaseName" & ";USER=user;PASSWORD=abcd")
If Cnn.State = adStateOpen Then
Debug.Print "Connection"
Else
Debug.Print "No Connection"
End If
Cnn.Close
I would recommend to use the SQL Proxy and then for the connection would be like if the database was in your localhost.
So the steps would be:
Install Cloud SQL Proxy in your computer
Start the cloud SQL Proxy
Connect as I f you were connecting to a local database
the code would be:
Dim Cnn As Object
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open ("DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=172.0.0.1;DATABASE=<DATABASENAME>;USER=<USERNAME>;PASSWORD=<PASSWORD>)
If Cnn.State = adStateOpen Then
Debug.Print "Connection"
Else
Debug.Print "No Connection"
End If
Cnn.Close
What kind of DB are you connection to? You can find all kinds of connection strings here.
https://www.connectionstrings.com/
Also, go to your ODBC drivers and see what you have installed. Your code has to match what you have installed. Here is an image of what I have on my system.
So, for instance, you have to have 'MySQL ODBC 5.3 Unicode Driver' installed because that's what you are referencing in your code. Try that and feed back with your findings and results.
I am trying to connect to Sybase ASE from VB and getting following error
Function createConnection() As ADODB.Connection
Dim ConnectString As String Dim ConnString As String
Set conn = New ADODB.Connection
.Mode = adModeReadWrite
.ConnectionTimeout = 15
.ConnectionString = "Provider=ASEOLEDB;" & _
"Server Name=" & Range("DBServerName") & _
";Initial Catalog=db;" & _
"User Id=user;" & _
"Password=password"
.Open
End With
Set createConnection = conn
End Function
Any help would be much appreciated.
I would suggest you fist to check odbcad as described here.
If you can find any mention of ASEOLEDB there, then you just have problem either with the app using wrong type of drivers (32-bit vs 64-bit) or with a connection string.
But as the error message suggests, you might be missing just the provider - same problem as here. These libraries are usually part of these installations:
SAP/Sybase ASE
SAP/Sybase ASE PC Client CD
SAP/Sybase ASE SDK
All of these can be acquired on SAP portal, however you need a login to that place as this software is accessible only on purchase. You can find here a link of PC Client CD content (Sybase infocenter website) and a manual on OLEDB here.
Unfortunately only freely downloadable ASE is for Linux, which is useless for you. Maybe you can find on that W7 machine installation media ...
Download & Install Provider
http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=19&Product=15
use below commands to register provider
regsvr32 sybdrvodb.dll
regsvr32 sybdrvodb64.dll
Details:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc20116.1550/html/aseodbc/aseodbc43.htm
we are currently retrieving data from our SQL Database for various purposes.
But we are shifting our Sql Database to a new Server. I need to change the Server link to the new server. I have tried changing the Server name in the Connection String at the Connection Properties window. But it doesnt work.
I have given the Connection Type Connection String details below for your reference.
The Server Name given in he below settings are Jr-erpsrv-02. I need to change this to Jr-erpsrv-03.
1) Connection Type : Database Query
DRIVER=SQL Server;SERVER=JR-ERPSRV-03;UID=Shakila;Trusted_Connection=Yes;APP=Microsoft Office XP;WSID=YFHO-WKSTATION
2) Connection Type : Database Query
DSN=Syspro;Description=Syspro;UID=ramya;Trusted_Connection=Yes;APP=2007 Microsoft Office system;WSID=ITSYSPRO-NB;DATABASE=SysproDSPL
3) Connection Type : Office Data Connection
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=SysproDSPL;Data Source=JR-ERPSRV-02;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=ACIT-PC1;Use Encryption for Data=False;Tag with column collation when possible=False
I'm trying to connect to an Oracle Database from an Excel application and whithout a DNS. I found on a website that it's possible to use ADO, so this is why I tried to do. I'm new to this so I juste copied what I found on this website.
Here is my code so far :
Sub ADOtest()
Dim connection As New ADODB.connection
connection.ConnectionString = "UID = user1; PWD= my_pwd; DRIVER = {Microsoft ODBC for Oracle; Server= localhost; Database= orcl.my_domain;"
connection.Open
End sub
When I run this code, I get an error saying that the driver was not found.
The problem is that I have no idea of what I have to do with the driver (how to install it and configure it). Plus, I don't know which one I should use : I've read that there is a driver from Microsoft, another one from Oracle and also I've seen something about providers like msdaora.
The program will be used by many users, so I would like to choose the solution that is the lightest (not much to install on computers).
Thank you !
For COM based ADO (ADODB) you can use the OLE DB Providers.
One is from Oracle, called "Oracle Provider for OLE DB". You can download it from 32-bit Oracle Data Access Components (ODAC) and NuGet Downloads (assuming your Excel is 32-bit). The connection string would be
"Provider=OraOLEDB.Oracle;Data Source=orcl;User ID=myUsername;Password=myPassword"
The other one is from Microsoft. Please note, this provider is deprecated, you should not use it for new projects. Usually it should be available on your Windows. Be aware, like the provider from Oracle it also requires an Oracle Client to be installed on the PC! The connection string would be
"Provider=MSDAORA;Data Source=orcl;User ID=myUsername;Password=myPassword"
The data source is usually defined in tnsnames.ora file or at a LDAP server, for example:
orcl.my_domain =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(Host = localhost)(Port = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
If you don't have such entry you can put everything into the connection string, e.g.
"Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=myUsername;Password=myPassword"
Perhaps you have to enclose the data source value by double-quotes ("), I am not sure.
So, in any case you would have to install an Oracle Client at all PC's.
Where is your database server hosted? In your question you say Server=localhost;, this would be quite unlikely, i.e. it is in contradiction to The program will be used by many users. I doubt everybody has an Oracle Database server installed on his local host.
The below connection string establishes connection with excel file which has extension as '.xls' but same string throws an exception while opening a connection with file which has extension as .xlsx.
Any idea?
ConnectionString = Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\abcd\Desktop\demo.xls; Extended Properties=excel 8.0; Persist Security Info=False
This is because you need a different connection string for xlsx'es.