Dear Friends,

Here I have tried to connect to Sybase Adaptive Server Anywhere 7.0 with the following code in C# as console application,
I am getting the ERROR: System.NullReference Exception occured in system.data.dll , this code executed after running the asademo.

Can you help me out where exactly I am going wrong!!!!!!

using System;
using System.Data;
using System.Data.OleDb;


namespace SybaseConnect
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            OleDbConnection myConnection =  new OleDbConnection(
                "Provider=ASAProv.70;uid=dba;pwd=sql;");
            //open the connection
            myConnection.Open();
            //Creating command object.
            OleDbCommand myCommand = myConnection.CreateCommand();
            //Specify query
            myCommand.CommandText = "Select fname, lname from Customer";
            //DataReader for the command
            OleDbDataReader myDataReader = myCommand.ExecuteReader();
            //Let's display data
            while ( myDataReader.Read())
            {
                Console.WriteLine("\t{0}\t{1}",
                    myDataReader["fname"],myDataReader["lname"]);
            }
            myDataReader.Close();
            myConnection.Close();

        }
    }
}

================================================ :)

Is it me, or are you not specifing a server in your connection string?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.