CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    1

    Not able to run this program. can someone help?

    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.

  2. #2
    Join Date
    Dec 2007
    Posts
    234

    Re: Not able to run this program. can someone help?

    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
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured