Connecting VBA with oracle 11g enterprise edition - oracle

I am trying to connect VBA to Oracle 11 g- I was checking whether the connection string was fine.
While trying below code I am getting error while opening the connection.
Runtime error-3706 Application defined or object -defined error.
Can anyone help?
Code:
Sub getdatafromOracle()
Dim connectdb As ADODB.Connection
connectdb.ConnectionString = "PROVIDER= OraOLEDB.Oracle;DATA SOURCE=DBname;USER ID=uname;PASSWORD=Pword"
connectdb.Open
connectdb.Close
End Sub

You habe to initialize the Connection object before you can use it.
set connectdb = New ADODB.Connection
Maybe you have to use this syntax (I am not sure):
connectdb.Open("PROVIDER=OraOLEDB.Oracle;DATA SOURCE=DBname", "uname", "Pword")

Related

Sage Line 50 ADODB connection with Classic ASP on IIS6 - Authentication Failed

We have a classic asp page running on IIS6, which connects to our Sage Line 50 (v17) with the following code:
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
Err.Clear
On Error Resume Next
adoCon.ConnectionTimeout = 0
ConStr="dsn=SageLine50v17;UID=uid;Password=pwd;"
adoCon.Open ConStr
If Err.Number <> 0 Then
Response.Write (Err.Description& "<br><br>")
Response.Write (Err.Number)
Response.End
End If
This works perfectly most of the time. However, occasionally, it throws the following error:
Authentication failed
-2147217843
My question is, what is causing the error? I'm thinking it is Sage throwing it back, but on searching for the error number (-2147217843!), I find nothing online.
I would test the DSN in excel or access then I would check the iis usr has permissions on the sage accdata folder :)

Database access issue with Visual Studio application

I has been created a program that works with MS Access 2010 (.accdb)extension. The program is fully works fine.
The issue is:
When the program is installed into another PC that has no MS Office installed, then the Exception that defined in the program returns connection error. Yes of course because the program can't read the (.accdb) file without office installed.
Need solution:
Is there any way to import this (.accdb) in order to read and modify it. Or is there any other simple solution that works when the application is installed to any non office installed PC?
The Demo of My program Code is:
Connection String:
Imports SpeechLib
Imports System.IO
Module MdlIPray5ve
Public con As OleDb.OleDbConnection
Public cmd As OleDb.OleDbCommand
Public sql As String
Public speaker As New SpVoice
Public Function connection() As String
Try
connection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=azan_time.accdb; Persist Security Info=False;"
Catch ex As Exception
MessageBox.Show("Could not connect to the Database. Check your Connection!")
End Try
End Function
Something that Accesses the Database:
Private Sub UpdateAlarmTone()
Try
Dim cmdText = "UPDATE alarm_tone SET subhi= #subhi1, zuhur =#zuhur1, aser = #aser1, megrib = #megrib1, isha = #isha1"
Using con As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(cmdText, con)
con.Open()
cmd.Parameters.AddWithValue("#subhi1", txtSubhi.Text)
cmd.Parameters.AddWithValue("#zuhur1", txtZuhur.Text)
cmd.Parameters.AddWithValue("#aser1", txtAser.Text)
cmd.Parameters.AddWithValue("#megrib1", txtMegrib.Text)
cmd.Parameters.AddWithValue("#isha1", txtIsha.Text)
Dim infor As String
infor = cmd.ExecuteNonQuery
If (infor > 0) Then
MsgBox("Alarm Tone record updated successfuly")
Else
MsgBox("Update failed!")
End If
End Using
End Using
Catch ex As Exception
MessageBox.Show("There is a problem with your connection!")
End Try
End Sub
create the Access database via ODBC, that comes with Windows itself.
You can also use other databases (eg., MySQL, Firebird, SQLite, and others) that are available that wouldn't necessarily cost your client anything if they installed it (or, for some, if you included it in your installation for them).
Using the MS Office COM automation requires that the MS Office product be installed on the machine running the automation.
There are third-party code libraries that replace that functionality with their own code, meaning your app could create it's own Access-compatible files. However, your users would still need Access to use them

Connection string in Visual Studio for Database Access

My Access database is password: (password is '123')
What is the connection code in C#?
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\My Project\DB.accdb;user=Admin;pwd=123";
cnn.open();
'ERROR Connection'
The correct connection string for Microsoft Access is something like this
#"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=G:\My Project\DB.accdb;
Jet OLEDB:Database Password=123;"
Of course you should use the appropriate provider. SqlConnection and the other classes from the namespace System.Data.SqlClient are used for Sql Server. Microsoft Access should uses the classes from the namespace System.Data.OleDb like OleDbConnection, OleDbCommand, OleDbDataReader etc...
This might help you out
Private connString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\My Project\DB.accdb;Jet OLEDB:Database Password=123;"
SqlConnection cnn = new SqlConnection(connString);
cnn.open();
//Do your Work
If you are using Microsoft Access accdb ODBC Driver
Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=G:\mydatabase.accdb;Uid=Admin;Pwd=123;

ORA-01019 connecting to Oracle from Excel

I have installed Oracle 10g Express Edition. When try to test the connection I am getting the error "Error while trying to retrieve text for error ORA-01019".
Below is my code.
strConnection = "Driver={Microsoft ODBC for
Oracle};Server=Servername;Uid=username;Pwd=password;"
Set conn = CreateObject("ADODB.Connection")
conn.Open strConnection
conn.Close
Set conn = Nothing
Thanks in advance
I had the following error occur recently.
System.Runtime.InteropServices.COMException (0x80004005): ORA-01019: unable to allocate memory in the user side
at ADODB.ConnectionClass.Open(String ConnectionString, String UserID, String Password, Int32 Options)
I managed to resolve the problem by simply modifying my connection string.
from:
"Provider=MSDAORA.1;Data Source=tprss;Persist Security Info=True;User ID=myUser;Password=myPassword"
To:
"Provider=MSDASQL;Data Source=tprss;Persist Security Info=True;User ID=myUser;Password=myPassword"
someone modified/updated the components on the box.
"ORA-01019 unable to allocate memory in the user side
Cause: The user side memory allocator returned an error.
Action: Increase the size of the process heap or switch to the old set of calls."
Followup from the comments:
Could you try this code?
Dim Cn As ADODB.Connection
Dim CP As ADODB.Command
Dim Rs As ADODB.Recordset
Dim Conn As String
Dim QSQL As String
'Connect to Oracele server begin
Conn = "DRIVER={ORACLE ODBC DRIVER};SERVER=Service name;UID=username;PWD=password;DBQ=Service name;DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TLO=O;"
Set Cn = New ADODB.Connection
With Cn
.ConnectionString = Conn
.CursorLocation = adUseClient
.Open
End With
If Cn.State = adStateOpen Then
MsgBox "Connection successful."
End If
'Connect to Oracle server end
'close connection begin
Cn.Close
Set Cn = Nothing
Set CP = Nothing
'close connection end
(This didnt fit in a Comment box)
You need at least one driver. The oracle driver is best but Microsoft Driver will work too.
Lets first try to make a connection string. Right click on your desktop and the create a new .txt file.
Now rename your textfile to something.udl
Double click on the udl file. Go to "Provider" and select Microsoft OLEDB Provider for Oracle. Then click on next. In the server name field you fill in your TNS name. Then username and password and put a V inside "Allow saving password" (we will need this) And click on test connection. Make sure this works.
If it works then click on OK. Now open the UDL file with a text editor. You will see something similar to:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS;Persist Security Info=True
Copy this part into your connection string:
Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS
Now your connection string should look like:
Conn = "Provider=MSDAORA.1;Password=yourpw;User ID=youruser;Data Source=yourTNS"
I hope this works.
We had the same problem, specifically on Windows 7 when using the Microsoft OleDb driver from VB6.
Following the instructions in this post fixed out problem:
http://prasanth4microsoft.blogspot.com/2010/11/windows7-excel-vba-ora-01019-unable-to.html
I had this problem also but it is on win10.. After I have tried a lots of different solution from web .. Finally.. it worked to change connection string to fix this problem.. But I changed "Provider=MSDAORA.1" to "Provider=OraOLEDB.Oracle"

How to create a object of java class in excel vba

i have a java class..i have registered in my system(it has shown the message as
registed successfully)..but when i try to create an object(the code is as below)
It is throwing error as module not found..do i have set the path.if yes how..
Dim conn
set conn = createObject("Main")
Main is the java class which is in C:\windows\java\trustlib
Please help me out..i am new to excel vba
See this description of CreateObject. Your code should look like this
Dim conn
Set conn = CreateObject("<server>.Main")
Where <server> is the name of the application providing the object.

Resources