[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 762
  • Last Modified:

How to connect to an Oracle Database in VB

I've connected many times to databases using a connection String placed in a Web Config file and the SQLConnection object.  I am trying to specify a connection to an Oracle database in a form based VB project.  Can anyone help me out with the syntax for that?
0
kpbarem
Asked:
kpbarem
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I would just look for an example like this. You mean something like that?
0
 
slightwv (䄆 Netminder) Commented:
0
 
käµfm³d 👽Commented:
Of course you are going to need an appropriate connection string, but you are also going to need an Oracle Client (unless you opt for the Instant Client, which I believe is a touch slower than the full blown client, but works quite nicely--in my experience).

Once you get the prerequisites, you can simply change your SqlConnection usage to OracleConnection--likewise for *Command objects. .NET comes with the System.Data.Oracle namespace, but it is my understanding that it is deprecated in favor of Oracle's own:  Oracle.DataAccess. To get that namespace, you will need to install ODP.NET. You might also find Oracle Data Access Components (ODAC) helpful.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
slightwv (䄆 Netminder) Commented:
OH,  Still .Net not VB6.  Sorry.

You can still use a config file with a console style app.  You can always hard code the connection string.

I don't have winform examples.

Here is a console app example I have using C#

using System;
using System.Data;

using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

public class Bob
{

	public static void Main(string[] args)
	{

			OracleConnection con = new OracleConnection();


 			string oradb = "Data Source=(DESCRIPTION="
          			+ "(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))"
          			+ "(CONNECT_DATA=(SERVICE_NAME=ORCL)));"
          			+ "User Id=scott;Password=tiger;";

			con = new OracleConnection(oradb);
			//con = new OracleConnection("User Id=bud;Password=bud;Data Source=bud");

			OracleCommand cmd = new OracleCommand();
			cmd.Connection = con;
			cmd.CommandText = " select count(*) from dual where dummy=:myVar ";

			OracleParameter param1 = cmd.Parameters.Add("myVar", OracleDbType.Varchar2);
			param1.Value = 'X';

			con.Open();


			Console.WriteLine("My result is: " + cmd.ExecuteScalar());

			con.Close();
			con.Dispose();

	}

}

Open in new window

0
 
käµfm³d 👽Commented:
You can always hard code the connection string.
Tsk tsk tsk...


:-P
0
 
kpbaremAuthor Commented:
This worked well thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now