Menu

#70 Object reference not set to an instance of an object.

open
nobody
None
5
2003-11-21
2003-11-21
David Smith
No

When I run this like of code

Line 78: Dim sql_u_session = db.sql_query("SELECT *
from " & SESSIONS_TABLE & " where session_id = '" &
user_session_id & "';")

I get "Object reference not set to an instance of an
object."

db.sql_query refers to a DAL that I have written in c#
to access multiple database types and have been trying
to run it on mysqlnet 0.73

public DataTable sql_query(string sqlstr)
{
try
{
DB_Start = DateTime.Now.Ticks / 10000000;
sqlstr = sqlstr.Replace("\\", "\\\\");

            queries += 1;

            DataTable MyTable;
            ByteFX.Data.MySqlClient.MySqlConnection

sqlConnection = new
ByteFX.Data.MySqlClient.MySqlConnection(connection_string);

            ByteFX.Data.MySqlClient.MySqlCommand sqlCommand =

new ByteFX.Data.MySqlClient.MySqlCommand(sqlstr,
sqlConnection);

            ByteFX.Data.MySqlClient.MySqlDataAdapter

dataAdapter = new
ByteFX.Data.MySqlClient.MySqlDataAdapter(sqlCommand);
System.Data.DataSet dataSet = new
System.Data.DataSet();
sqlConnection.Open();
dataAdapter.Fill(dataSet);
sqlConnection.Close();

            MyTable = new DataTable\(\);
            MyTable = dataSet.Tables\[0\];

            total\_db\_time += DateTime.Now.Ticks / 10000000 -

DB_Start;

            return MyTable;
        \}
        catch \(InvalidCastException ex\)
        \{
            Trace.Warn\("SQL Error",sqlstr + "<br />" +

ex.ToString());
return new DataTable();
}

    \}

I have the .net framework 1.1 install on windows 2000
professional

do you have any ideas on what I am doing wrong?

Discussion

  • Reggie Burnett

    Reggie Burnett - 2003-11-24

    Logged In: YES
    user_id=523261

    First, you should not create a new table object before you
    get a reference to the tables in the dataset.

    I don't see anything other than that obviously wrong. Can
    you debug your code and tell me which line gives you this
    error?

    -reggie

     
  • David Smith

    David Smith - 2003-11-25

    Logged In: YES
    user_id=420754

    I get the error reporting to this

    Object reference not set to an instance of an object.
    at ByteFX.Data.MySqlClient.Driver.Authenticate(String
    userid, String password, Boolean UseCompression)
    at ByteFX.Data.MySqlClient.Driver.Open(String host, Int32
    port, String userid, String password, Boolean
    UseCompression, Int32 connectTimeout)
    at ByteFX.Data.MySqlClient.MySqlInternalConnection.Open()
    at
    ByteFX.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
    at ByteFX.Data.MySqlClient.MySqlPool.GetPooledConnection()
    at ByteFX.Data.MySqlClient.MySqlPool.GetConnection()
    at
    ByteFX.Data.MySqlClient.MySqlPoolManager.GetConnection(MySqlConnectionString
    settings)
    at ByteFX.Data.MySqlClient.MySqlConnection.Open()
    at dataclass.db_mysql.sql_query(String sqlstr)
    at dataclass.db_mysql.sql_query(String sqlstr, Boolean cache)
    at dataclass.db.sql_query(String sqlstr)
    at ASP.default_aspx.Page_sessions() in
    c:\inetpub\wwwroot\aspxnet\ASPXlinks2\includes\sessions.aspx:line
    78
    at ASP.default_aspx.Page_header() in
    c:\inetpub\wwwroot\aspxnet\ASPXlinks2\includes\page_header.aspx:line
    40
    at ASP.default_aspx.Page_Load() in
    c:\inetpub\wwwroot\aspxnet\ASPXlinks2\Default.aspx:line 23
    at
    System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object
    sender, EventArgs e)
    at System.Web.UI.Control.OnLoad(EventArgs e)
    at System.Web.UI.Control.LoadRecursive()
    at System.Web.UI.Page.ProcessRequestMain()

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.