Have a look at the following Oracle article for the basics on connecting to the database from .NET
It shows how to connect to the database and retrieve records using SELECT statements. To perform inserts and updates you just need to change de command text with the appropriate SQL command, and execute it as non reader (i.e. replacing cmd.ExecuteReader with cmd.ExecuteNonReader).
<a href="http://www.oracle.com/technology/pub/articles/cook-vs08.html">Build a .NET Application on the Oracle Database with Visual Studio 2005 or 2008</a>
Last Wiki Answer Submitted: March 11, 2009 2:00 pm by carlosdl63,535 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
Dim oradb As String = “Data Source=localhost;User Id=shazia;Password=shazia;”
Dim oradb As String = “Data Source=(DESCRIPTION=” _
+ “(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=shazia;Password=shazia;”
Dim conn As New OracleConnection(oradb)
Dim conn As New OracleConnection() ‘ Visual Basic
conn.ConnectionString = oradb
conn.Open()
MsgBox(“connected successfully”)
iam getting errors such as
Error 1 Statement is not valid in a namespace. C:Documents and SettingsShazia (Delonti)My DocumentsVisual Studio 2005ProjectsschoolschoolAdd Admission.vb 4 1 school
plz give me a solution for this .iam new vb.net
Thanks once again
In .NET, everything have to be inside a class or module (excluding the imports).
Also, there are some unnecessary lines in your code, for example the lines where you set the connection string.
If you want to avoid the use of the TNSNAMES.ORA file then use your second option:
Dim oradb As String = “Data Source=(DESCRIPTION=” _
+ “(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=shazia;Password=shazia;”
Otherwise, use this (but replace ‘localhost’ with the database alias defined in your tnsnames.ora file):
Dim oradb As String = “Data Source=your_database_alias;User Id=shazia;Password=shazia;”
Your code should look similar to this:
Imports Oracle.DataAccess.Client
Public Class MainClass
Shared Sub Main()
Dim oradb As String = “Data Source=(DESCRIPTION=” _
+ “(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=shazia;Password=shazia;”
Dim conn As New OracleConnection(oradb)
conn.Open()
End Sub
End Class
Thank u for helping me out .I have implemented the code which u have given .Now it is giving as error connection not open ora 6413.Plz give solution for that
Thanks Carlosdl for giving me the answer ,i will work out with this
Imports Oracle.DataAccess.Client
Dim oradb As String = “Data Source=localhost;User Id=shazia;Password=shazia;”
Dim oradb As String = “Data Source=(DESCRIPTION=” _
+ “(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=shazia;Password=shazia;”
Dim conn As New OracleConnection(oradb)
Dim conn As New OracleConnection() ‘ Visual Basic
conn.ConnectionString = oradb
conn.Open()
MsgBox(“connected successfully”)
iam getting errors such as
Error 1 Statement is not valid in a namespace. C:Documents and SettingsShazia (Delonti)My DocumentsVisual Studio 2005ProjectsschoolschoolAdd Admission.vb 4 1 school
plz give me a solution for this .iam new vb.net
Thanks once again
In .NET, everything have to be inside a class or module (excluding the imports).
Also, there are some unnecessary lines in your code, for example the lines where you set the connection string.
If you want to avoid the use of the TNSNAMES.ORA file then use your second option:
Dim oradb As String = “Data Source=(DESCRIPTION=” _
+ “(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=shazia;Password=shazia;”
Otherwise, use this (but replace ‘localhost’ with the database alias defined in your tnsnames.ora file):
Dim oradb As String = “Data Source=your_database_alias;User Id=shazia;Password=shazia;”
Your code should look similar to this:
Imports Oracle.DataAccess.Client
Public Class MainClass
Shared Sub Main()
Dim oradb As String = “Data Source=(DESCRIPTION=” _
+ “(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=shazia;Password=shazia;”
Dim conn As New OracleConnection(oradb)
conn.Open()
End Sub
End Class
Hi Carlosdl,
Thank u for helping me out .I have implemented the code which u have given .Now it is giving as error connection not open ora 6413.Plz give solution for that
Thanks & Regards,
shazia.
I posted an answer here:
Solution for ORA-6413 error showing connection not open
See if it helps.