Click to See Complete Forum and Search --> : Not able to run this program. can someone help?


Ndnet
August 9th, 2010, 06:40 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB;Data Source=140.158.128.14,1433;Initial Catalog=dbturing;User ID=group3;Password=group3");
OleDbDataReader rdr = null;

try
{
conn.Open();
OleDbCommand cmd=null;
try
{
cmd = new OleDbCommand("Select Dname from Department", conn);
}
catch(OleDbException exception)
{
for (int i=0; i < exception.Errors.Count; i++)
{
Console.WriteLine("Index #" + i + "\n" +
"Message: " + exception.Errors[i].Message + "\n" +
"Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
"Source: " + exception.Errors[i].Source + "\n" +
"SQL: " + exception.Errors[i].SQLState + "\n");
}
}

rdr = cmd.ExecuteReader();

while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{
if (rdr != null)
rdr.Close();
if (conn != null)
conn.Close();
}
}
}
}


I am trying to connect to a database that has been created in Oracle SQL developer and I keep getting this exception "SQL server does not exist or access denied" at conn.Open();

Somebody please help me.

TechGnome
August 11th, 2010, 08:45 AM
1) If you're connecting to Oracle, you're using the wrong provider - SQLOLEDB is for SQL Server.
2) You should look for the Oracle .NET ADO connector and use that instead. Might make things easier.

-tg