473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

try to access MySQL in ASP.NET but output error

2
Hi

I tried to use following code to access MySQL database but the error 'Object reference not set to an instance of an object' was happened:
Expand|Select|Wrap|Line Numbers
  1. Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=xxxx; UID=xxxx; PASSWORD=xxxx; OPTION=3"
  2. Dim MyConnection As New System.Data.Odbc.OdbcConnection(MyConString)
  3.  
  4. Dim SQL As String = "SELECT * FROM registration_code"
  5. Dim MyCommand As New System.Data.Odbc.OdbcCommand
  6. MyCommand = New System.Data.Odbc.OdbcCommand(SQL, MyConnection)
  7.  
  8. MyConnection.Open()
  9.  
  10. Dim dr As System.Data.Odbc.OdbcDataReader
  11. dr = MyCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection Or System.Data.CommandBehavior.SingleResult)
  12.  
  13. While dr.Read()
  14. ...
  15. Loop
  16.  
  17. MyConnection.Close()
  18.  

The error shown as like:
Expand|Select|Wrap|Line Numbers
  1. Object reference not set to an instance of an object. 
  2. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  3.  
  4. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  5.  
Is there anybody know where my codes wrong?

Thanks

Gary
Sep 7 '07 #1
1 1593
r035198x
13,262 8TB
Hi

I tried to use following code to access MySQL database but the error 'Object reference not set to an instance of an object' was happened:
Expand|Select|Wrap|Line Numbers
  1. Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=xxxx; UID=xxxx; PASSWORD=xxxx; OPTION=3"
  2. Dim MyConnection As New System.Data.Odbc.OdbcConnection(MyConString)
  3.  
  4. Dim SQL As String = "SELECT * FROM registration_code"
  5. Dim MyCommand As New System.Data.Odbc.OdbcCommand
  6. MyCommand = New System.Data.Odbc.OdbcCommand(SQL, MyConnection)
  7.  
  8. MyConnection.Open()
  9.  
  10. Dim dr As System.Data.Odbc.OdbcDataReader
  11. dr = MyCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection Or System.Data.CommandBehavior.SingleResult)
  12.  
  13. While dr.Read()
  14. ...
  15. Loop
  16.  
  17. MyConnection.Close()
  18.  

The error shown as like:
Expand|Select|Wrap|Line Numbers
  1. Object reference not set to an instance of an object. 
  2. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  3.  
  4. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
  5.  
Is there anybody know where my codes wrong?

Thanks

Gary
You are derefencing a null variable somewhere in your code.
You may want to ask in the .NET forum if you can't figure out where the null pointer is occuring.
Sep 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael J. Astrauskas | last post by:
I have a site where a user logs in and a session variable I created is used to keep track of the fact that the user is logged in. This various pages query a MySQL database to get information...
11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
15
by: Pres | last post by:
I am not an experienced programmer. I do have a question regarding workday calculations. I have 3 fields. CURDATE, NUMDAYS, CALCDATE After entering the first two fields, normally the current...
2
by: SKB | last post by:
Hi, I am absolutely new to this area. I am getting the following difficulty : Access denied for user 'ODBC'@'localhost' (using password: NO) when I try the mysql command from within the...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
7
by: rajbala.3399 | last post by:
Hi , I want to download sql in my linux system........... # rpm -ivh MySQL-server-5.0.24a-0.glibc23.i386.rpm MySQL-cl ient-5.0.24a-0.glibc23.i386.rpm Preparing... ...
5
by: Jagadish Kumar, Maripi | last post by:
Hi, I got the following error while trying to compile php with mysql. I would be glad if anyone can help me on this. Here is the error that i've got in config.log The command i used is:...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
0
by: laxgb | last post by:
Hi I tried to use following code to access MySQL database but the error 'Object reference not set to an instance of an object' was happened: Dim MyConString As String = "DRIVER={MySQL ODBC 3.51...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.