Wilder1626
asked on
VB.Net - Connection string to Oracle 11g dbase
Hi
In my previous VB6 application, i was able to connect to my oracle 11g tables using the connection:
Now that i'm creating a new application using Visual Studio 2019 with a vb form and a DataGridView1, i would like to pull data the same way.
So i tried with:
Thank you for your help.
In my previous VB6 application, i was able to connect to my oracle 11g tables using the connection:
oconn.Open "Provider=OraOLEDB.Oracle.1;Data Source=DataSouceName;User Id=UserId;Password=Password;"
Now that i'm creating a new application using Visual Studio 2019 with a vb form and a DataGridView1, i would like to pull data the same way.
So i tried with:
Imports System.Data.SqlClient
Imports OracleConnection = Oracle.ManagedDataAccess.Client.OracleConnection
Imports OracleCommand = Oracle.ManagedDataAccess.Client.OracleCommand
Imports OracleDataReader = Oracle.ManagedDataAccess.Client.OracleDataReader
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
cn.ConnectionString = "Provider=OraOLEDB.Oracle.1;Data Source=DataSourceName;User Id=UserId;Password=Password;"
Try
cn.Open()
Dim da As New SqlDataAdapter("Select * from Location", cn)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
But i'm getting the error:System.ArgumentException
HResult=0x80070057
Message=Keyword not supported: 'provider'.
Source=System.Data.SqlClient
Would you know how i can fix this problem?Thank you for your help.
ASKER
When using it, i get the error:
System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
Which libraries are being used/referenced?!
https://stackoverflow.com/questions/49159199/connect-to-oracle-database-in-dotnet-mvc-application
https://stackoverflow.com/questions/49159199/connect-to-oracle-database-in-dotnet-mvc-application
ASKER
I've installed below NuGets.
Do i need references?
And i've imported below:
Imports System.Data.SqlClient
Imports OracleConnection = Oracle.ManagedDataAccess.Client.OracleConnection
Imports OracleCommand = Oracle.ManagedDataAccess.Client.OracleCommand
Imports OracleDataReader = Oracle.ManagedDataAccess.Client.OracleDataReader
Do i need references?
And i've imported below:
Imports System.Data.SqlClient
Imports OracleConnection = Oracle.ManagedDataAccess.Client.OracleConnection
Imports OracleCommand = Oracle.ManagedDataAccess.Client.OracleCommand
Imports OracleDataReader = Oracle.ManagedDataAccess.Client.OracleDataReader
ASKER
I don't know if this can also help:
Error: Oracle.ManagedDataAccess.Client.OracleException: 'Connection request timed out'
on code: conn.Open()
Error detail:
Error: Oracle.ManagedDataAccess.Client.OracleException: 'Connection request timed out'
on code: conn.Open()
Dim oradb As String = "Data Source=i2_DV791;User Id=jdatm_dev;Password=jdatm_dev;"
Dim conn As New OracleConnection(oradb)
conn.Open()
Error detail:
Oracle.ManagedDataAccess.Client.OracleException
HResult=0x80004005
Message=Connection request timed out
Source=Oracle Data Provider for .NET, Managed Driver
StackTrace:
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
Which DLLs have you references then?!
According to https://stackoverflow.com/questions/49159199/connect-to-oracle-database-in-dotnet-mvc-application
it might be the wrong ones...
According to https://stackoverflow.com/questions/49159199/connect-to-oracle-database-in-dotnet-mvc-application
it might be the wrong ones...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it's kind of weird cause on my side, i dont see the folder References. I see Dependencies
When i right click on it, i get
Then if i click Project References...
In the link you provided, it was mentioning: Oracle.ManagedDataAccess.Core.dll Oracle.ManagedDataAccess.Core.dll
May be the problem.
When i right click on it, i get
Then if i click Project References...
In the link you provided, it was mentioning: Oracle.ManagedDataAccess.Core.dll Oracle.ManagedDataAccess.Core.dll
May be the problem.
ASKER
I'm getting the error when using:
System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
Dim oradb As String = "Data Source=i2_DV791;User Id=jdatm_dev;Password=jdatm_dev;Pooling=False" Dim conn As New OracleConnection(oradb) conn.Open()
System.TypeLoadException: 'Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
I think so! Try to exchange those references!
In the link you provided, it was mentioning: Oracle.ManagedDataAccess.Core.dll Oracle.ManagedDataAccess.Core.dll
May be the problem.
ASKER
Ok, i've followed the other link and i have uninstalled Oracle.ManagedDataAccess and only kept: Oracle.ManagedDataAccess.Core.
I have also removed from the PackageReference below:
Now i just need to find: Oracle.ManagedDataAccess.Core.dll . I don't see it at all.
But now i have a new error:
I have also removed from the PackageReference below:
Oracle.ManagedDataAccess
Now i just need to find: Oracle.ManagedDataAccess.Core.dll . I don't see it at all.
But now i have a new error:
Oracle.ManagedDataAccess.Client.OracleException: 'ORA-12154: TNS:could not resolve the connect identifier specified'
ORA-12154: TNS:could not resolve the connect identifier specifiedBingo ;-) We're getting closer :-))
Take a look at this, regarding your TNSNAMES.ORA (whereas you may also use a TNS-less connection string there):
https://stackoverflow.com/questions/31564288/connecting-to-oracle-using-oracle-manageddataaccess
ASKER
Great ;-) no more error. Thanks for your guidance. So appreciated.
Now i just need to feed the DataGridView1 with the data. That portion of the code
I'm now having an error on SqlDataAdapter
Now i just need to feed the DataGridView1 with the data. That portion of the code
Dim da As New SqlDataAdapter("Select * from Location", conn)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
I'm now having an error on SqlDataAdapter
I think, you still have some (brain) bugs involved in the actual code ;-) *just kidding*
Take a look at the examples shown here:
https://docs.oracle.com/cd/E18283_01/appdev.112/e10767/building_odp.htm
Especially this part:
Take a look at the examples shown here:
https://docs.oracle.com/cd/E18283_01/appdev.112/e10767/building_odp.htm
Especially this part:
conn.Open() connect.Enabled = False
Dim sql As String = "select * from departments where department_id < 60"
cmd = New OracleCommand(sql, conn)
cmd.CommandType = CommandType.Text
da = New OracleDataAdapter(cmd)
cb = New OracleCommandBuilder(da)
ds = New DataSet()
da.Fill(ds)
departments.DataSource = ds.Tables(0)
ASKER
you still have some (brain) bugs involved in the actual codeYes i do. Ha ha ha
I actually added to the Public class
Dim conn As New OracleConnection
Private cmd As OracleCommand
Private da As OracleDataAdapter
Private cb As OracleCommandBuilder
Private ds As DataSet
Then, on the Click button, i've added below code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim oradb As String = "Data Source=DataSource;User Id=UserId;Password=Password;"
Dim conn As New OracleConnection(oradb)
Dim connect As Object = Nothing
Try
conn.Open()
connect.Enabled = False
Dim sql As String = "Select * from Location"
cmd = New OracleCommand(sql, conn)
cmd.CommandType = CommandType.Text
da = New OracleDataAdapter(cmd)
cb = New OracleCommandBuilder(da)
ds = New DataSet()
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
Catch ex As Exception
End Try
End Sub
I started to get the error on :da = New OracleDataAdapter(cmd)
(field) Form1.cmd AsOracleCommand
BC30311: Value of type 'OracleCommand' cannot be converted to 'OracleCommand'
From what i read on the link, I should not have to do anything else, if i did read it correctly. I will review again, just in case.
ASKER
omg. It's getting worst.
Now i'm at below error. ha ha ha
System.InvalidOperationException: 'Application-defined or object-defined error.'
1 of 2 Inner Exceptions:
TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.
2 of 2 Inner Exceptions:
OracleException: The provider is not compatible with the version of Oracle client
Now i'm at below error. ha ha ha
System.InvalidOperationException: 'Application-defined or object-defined error.'
1 of 2 Inner Exceptions:
TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.
2 of 2 Inner Exceptions:
OracleException: The provider is not compatible with the version of Oracle client
ASKER
i'm starting to think that i should try to re-install Oracle 11g
Don't get me wrong, but you cannot just Copy&Paste this stuff into your code without adopting!!
You will never get a real Oracle DB connection with these values!
The other problem is setting the "connect" object to "Nothing" and trying to access its non-existing propery "Enabled" afterwards!
You will never get a real Oracle DB connection with these values!
The other problem is setting the "connect" object to "Nothing" and trying to access its non-existing propery "Enabled" afterwards!
ASKER
I'm going to take a step back and try to figure out what's going on. I've tried so many things with no good results that I may be a little mixt-up right now. vb.net is pretty new to me as well.
But thanks for your help.
But thanks for your help.
No problem ;-)
Never make to many changes at once! Just one step at a time (at least in this case)...
Never make to many changes at once! Just one step at a time (at least in this case)...
ASKER
thanks for the advice. I will definitely follow your recommendation and take it one step at the time. :-)
Open in new window
https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/2015/getting_started_vb_version/oracle_data_provider_for_dotnet_vb_version.html