Changing VBA ADODB Connection String, Need To Be More Specific - oracle

I have a working excel macro that connects using the following connection type:
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open ( _
"User ID=userid" & _
";Password=pass" & _
";Data Source=blank.blank.com" & _
";Provider=MSDAORA.1")
I can connect in one part of my network but when I try to use the same macro on another computer I can no longer connect. My thought is there is a networking issue and I need to be "more specific". So after some googling I've come across other data connection strings that utilize IP and port name.
Driver={Microsoft ODBC for Oracle};
Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=199.199.199.199)(PORT=1523))(CONNECT_DATA=(SID=dbName)));
Uid=myUsername;Pwd=myPassword;
Coming from https://www.connectionstrings.com/microsoft-odbc-for-oracle/
Following Microsofts documentation then I get the following:
With cn
.Provider = "MSDAORA.1"
.ConnectionString = "Driver={Microsoft ODBC for Oracle};" & _
"Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=1.1.1.1)(PORT=xxxx))(CONNECT_DATA=(SID=DB)));" & _
"Uid=userid;Pwd=pass;"
.Open
End With
However I get an error: ORA-12560 TNS:Protocol adapter error
Some solutions indicate that I should restart the database, but it's running! I connect to it just fine the other way.
Does anyone have a better way of connecting "more specifically" that might help my networking problem or might be able to help me fix up my new way of connecting?

I have always used the option you originally used. The fact that it works on one machine and does not work on another indicates to me that you do not have the MSDAORA driver installed on the second computer. The machine requires that the ODBC driver exists on the machine for your code to function.
Go to ODBC and make sure you can create a test connection via the ODBC panel on the second machine to make sure ODBC is functional for the MSDAORA driver.
I see there is no test connection when using Microsoft ODBC for Oracle. There is for the Oracle driver. One way to test it is to open MS Access and create a linked table, using the Microsoft ODBC connection you created. It will prompt you for a password and if it succeeds you will link the table, and know it is working, or it will give you an ODBC error, and you will know it is not.
Or you could use the Oracle driver, which would require installing the Oracle Client driver, and changing your connection information to reflect that driver instead of the MS one.

This works fine for me:
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open ( _
"User ID=userid" & _
";Password=pass" & _
";Data Source=blank.blank.com" & _
";Provider=MSDAORA.1")

Related

Connection string to connect to oracle 11g from classic asp

I set up an ODBC connection using ODBC Data Source Administrator . I have named it "BIOTPL" connect like this:
The corresponding code is :
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "Provider=OraOLEDB.Oracle;Data Source=simple_dsn;User Id=USER;Password=PASSWORD;"
But I am getting this error .
ORA-12154: TNS:could not resolve the connect identifier specified
How can I solve this error ? Please help me .
The following code works for me .
Set Conn = Server.Createobject("ADODB.Connection")
Conn.open "Driver={Oracle in OraDb11g_home1};Server=10.11.201.170; Uid=USER;Pwd=PASSWORD;"
This is how I connect to Oracle using VBscript.
ConnectionString = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + DBCONN + ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" + DatabaseSID + " ))); uid=" + DatabaseUser + ";pwd=" + DatabasePassword + ";"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open ConnectionString
I had a similar error when using classic ASP and Conn.Open "Provider=OraOLEDB.Oracle..." as is shown in the code above.
However, if I used Conn.Open "DSN=MyDSN;User ID=..." the connection worked.
In order to use the "Provider=OraOLEDB.Oracle..." syntax, I had to create a 32-bit application pool in IIS - create the application pool, then set Enable 32-Bit Applications = True (in advanced settings).
Note that 64-bit Windows has both 32 and 64-bit ODBC configurations. The default ODBC manager is 64-bit. Classic ASP applications can run in 64-bit mode and use 64-bit ODBC DSNs with some limitations like using Conn.Open "DSN=MyDSN;User ID=...".
If you use the Conn.Open "DSN=MyDSN..." syntax and you run in 32-bit mode, you will need to configure the DSN using the 32-bit ODBC manager. To access the 32-bit ODBC manager, run C:\Windows\SysWOW64\odbcad32.exe
The 32-bit and 64-bit ODBC manager windows look identical - there will just be different lists of DSNs that are configured.
One other tool that I found helpful is to create a file named DBConnection.udl. (The file name is not important - just the .udl suffix.) When you double-click the file, a Data Link Properties window will open and allow you to select the provider and connection info. There is also a test button to verify your connection. After setting the connection variables, close the window and open the DBConnection.udl file with a text editor (notepad.exe works) and it will display the OLEDB init string that can be used in your application.

Fatal two-task communication protocol error in oracle 10 g

I'm using QTP 10.
Trying to connect to Oracle DB via oracle client 10.2(windows xp).
I had prev oracle 9i & i've upgraded it to 10.2 thought it would resolve.
But still i'm getting "fatal two-task communication protocol error".
Is there any solution for that .
i see the same client version is working with windows 7 & oracle 10.2.
Appreciate your help..
I am using ADODB to connect to Oracle 10 and 11 from QTP (from VBScript in generall).
The code to connect is:
Set connection = createobject("adodb.connection")
connection.open "Driver={Microsoft ODBC for Oracle};" + _
"Server=host:1521/database_sid;Uid=username;Pwd=password;"
where:
host - is a server name where Oracle is running
1521 - is a port number (1521 is default port, but could be different on your system)
database_sid - is a SID of the database
You need to ask your database administrator for these values.
This code requires Oracle Instant Client.
You need to download proper package for your system (Win 32, Win 64 etc.) from here: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Unpack it to any directory and place this directory in a PATH environment variable.
and then, the code to execute queries and get results looks like this:
Set rs = createobject("adodb.recordset")
rs.open "SELECT fieldname FROM table WHERE etc.", connection
while not rs.eof
value = rs.fields( "fieldname" )
.....
loop

Error connecting to Oracle with Classic ASP on IIS7

I just replaced the hard drive on my Windows 7 machine (my development computer). I did not have any issues with this working on the old hard drive, but I think I remember I had to change something or install something, but I do not remember.
The following code works perfectly on my live machine (Windows 2003 with IIS6).
OracleConn = "Provider=MSDASQL.1;Persist Security Info=True;User ID=TheUID;Password=ThePW;DSN=TheDB;DBQ=ORA_PRD1;"
SqlStr = "SELECT * FROM TestTable WHERE Somefield = 'Something'"
Set Objrs = Server.CreateObject("ADODB.RecordSet")
Objrs.Open SqlStr, OracleConn, adOpenStatic, adLockOptimistic,adCmdText
While Not Objrs.EOF
Response.Write "Some Stuff and whatever <br>"
Objrs.MoveNext
Wend
Objrs.Close
Set Objrs = Nothing
When I run it, I am getting the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
I did create a .udl file to get the connection string and to test the database connection and it works fine. I also have an app on my computer that uses the same ODBC drivers to connect to the same database and it works fine.
I dont have any issues connecting to an Access database at all. Connecting to Oracle seems to be the only issue I am having.

accessing xampp database on remote computer using visual basic 6

hi everyone i need help.
i have a simple visual basic 6 application that stores data on a xampp database. it works fine when i access my database locally using the following code:
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Sub main()
Set cn = New ADODB.Connection
cn.ConnectionString = "Driver={MySql ODBC 3.51 Driver}; Server=localhost; Port=3306; database=MY_DATABASE; user=root; password=; option=3;"
cn.Open
End Sub
now i copied the visual basic application i was using and paste it to a networked computer and did some modification on the code to access the xampp database stored on another computer. here is the code
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Sub main()
Set cn = New ADODB.Connection
cn.ConnectionString = "Driver={MySql ODBC 3.51 Driver}; Server=\\192.100.50.2\choco; Port=3306; database=MY_DATABASE; user=root; password=; option=3;"
cn.Open
192.100.50.2 is the ip address and choco is the computer name of the computer where the xampp database was stored. my problem is i cannot access the xampp databae and i got a run error "Unknown MySQL serve host '\192.100.50.2\choey'[1106]". please help me. thanks in advanced.
I think part of the problem, is your using "root" remotely.
1. REALLY bad idea.
Create a user just for your app.
2. Root by default can't be used remotely.
3. Use your servers name or address but not both.
Side note, it's not a XAMPP Database, it's MySQL.

ORA-12638: Credential retrieval failed

I have a legacy VB6 application which I've inherited. The issue I'm facing is that I'm getting the infamous
ORA-12638: Credential retrieval failed
error message whenever it tries to connect to one of our Oracle databases. I can connect fine from SQLPlus and Toad, however. I've Googled around and everyone seems to say that modifying their sqlnet.ora file to
SQLNET.AUTHENTICATION_SERVICES=(NONE)
did the trick. I have yet to find anyone with an alternative fix. Here is what my connection string looks like:
"PROVIDER=OraOLEDB.Oracle;DATA SOURCE=(DESCRIPTION = " & _
"(ADDRESS = (PROTOCOL = TCP)(HOST = server1)
(PORT = 1521))" & _
"(ADDRESS = (PROTOCOL = TCP)(HOST = server2)
(PORT = 1521))" & _
"(LOAD_BALANCE = yes) " & _
"(CONNECT_DATA = " & _
"(SERVER = DEDICATED) " & _
"(SERVICE_NAME = database_name_here) " & _
") " & _
"); " & _
"User Id=username_here;Password=password_here;"
As for my VB code, it's quite simple.
Private oracleDatabaseConnection As ADODB.Connection
Set oracleDatabaseConnection = New ADODB.Connection
oracleDatabaseConnection.Open oracleConnectionString
Anyone have any ideas?
Thank you. :)
I know this is a very old post but I have found a solution that has worked for me (Legacy VB6 Application):
Change the following entry in the sqlnet.ora file:
Original Entry - SQLNET.AUTHENTICATION_SERVICES= (NTS)
Modified Entry - SQLNET.AUTHENTICATION_SERVICES= (NONE)
Here is a LINK to the solution
Honestly this is one of those errors that can be caused by lots of different root problems.
On the assumption your database server is Windows, check its event log, both System and Application. You may find something there that is useful.
I have encountered this error in some cases because the account under which the Oracle service was running got locked.
I have also encountered it in cases where we never found the explanation, but we were always able to clear up the issue by having the user lock and unlock their PC.
Is the VB application running on a different machine than the client that can connect? If so, is it possible to test using a different client program on the same machine -- or is it possible to try the VB application on your machine?
Know it's an old question but it has started appearing with the recent Windows update.
The way to easily solve it is to set
SQLNET.AUTHENTICATION_SERVICES= (NONE)
in the sqlnet.ora.
If you are running a web app under IIS, restarting IIS seem to help. But this is one sucker of an issue that has not much reasoning behind.
I installed Oracle Database 11g Express Edition 32-bit on Windows 10 professional 64-bit (spanish edition).
After restart PC all works ok.
But the next day I get error using SQL*PLus and SQLTools 1.9 build 15:
ORA-12638: Credential retrieval failed
I modified the sqlnet.ora file so:
SQLNET.AUTHENTICATION_SERVICES= (NONE)
and now I can connect using SQLPlus, SQLTools 1.9 build 15.
If using IIS and for a VB app, it may help to create a new Data Source in the ODBC manager and referencing it by name (instead of by provider) in the connection string.
For example, if the name for the Data Source is "test_ds", I would replace
ObjConn.open "Provider=MSDAORA;User ID=myuser;password=mypassword;Data Source=MYDATASOURCEFROMTNSNAMES;Persist Security Info=False"
for
ObjConn.open "dsn=test_ds;pwd=mypassword"
Can't really explain the logic behind the solution, but it worked for me.
Note also that Windows client connections can fail with this error, when using Windows Hello login.
Whatever windows authentication for a connect like:
sqlplus un/pw#Dev
failed with ora-12638, when I logged into my laptop with Face recognition (ie. using Hello)
To get around this, either set SQLNET.AUTHENTICATION_SERVICES = (NONE)
or just login with your tradition windows username and password.

Resources