DataAdapter.Fill(dataset): Null exception

S

Stanav

Hello all,
I'm developing a web application using VB.Net 2003 and Framework 1.1. This
application queries an AS/400 database. I'm using the IBM OleDb provider
that came with IBM Client Access for Windows (V5R3). Everything works fine
on my development PC, but when I move the application to a Windows Server
2003, it crashes when trying to fill a dataset. I've double-checked that the
Win 2k3 server does have Client Access installed, that it has .NET Framework
1.1, and running IIS. The only difference between my development PC and the
2k3 Server is that my PC is running WinXP Pro (thus it runs IIS v.5.1) while
the server is running IIS v.6.0.
Here is my code:

Public Sub LoadDataSet(ByVal source As String, ByVal Collection As String, _
ByVal table As String, ByVal field As String, ByVal
keyValue As String)

'Connection string to as400 database
conStr400 = "Provider=IBMDA400;Data Source=" & source & _
";User ID=myID;Password=myPwd;DEFAULT COLLECTION=" &
Collection
'Create connection object
conn400 = New OleDb.OleDbConnection(conStr400)

'Building SQL select string
Dim selStr As String = "SELECT " & selectedFields & " FROM " & table
& _
" WHERE " & field & " = " & keyValue & " ORDER
BY DSNUMB"

'Create data adapter
da = New OleDb.OleDbDataAdapter(selStr, conn400)

Dim count As Integer = 0

'Open connection to database. The Response.Write statements are for
debugging purpose only

Response.Write("Conn State before open: " & conn400.State & "<br>")
<----- shows "0"

conn400.Open()

Response.Write("Conn State after open: " & conn400.State & "<br>")
<----- shows "1": connected

'Try to load dataset
Try
ds.Clear()

Response.Write("Before Fill: " & ds.Tables.Count & "<br>")
<----- shows "Before Fill: 0" : ds was created, just doesn't have any data,
yet.

count = da.Fill(ds) <---- Null Exception occurs here

Response.Write("After Fill: " & ds.Tables.Count & "<br>Rec count
= " & count) <----- Doesn't show anything

Catch ex As Exception

TextBox2.Text = "Fill Error: " & ex.Message <------ Shows
"Object reference not set to an instance of the object."
Finally
conn400.Close()
Response.Write("Conn State after close: " & conn400.State &
"<br>") <---- Shows "Finally: 0"
End Try
End Sub

At the line of code where that causes exception, the only objects referred
are the Data Adapter "da" and the DataSet "ds".
The dataset "ds" is not the problem because I can count the number of tables
in it before the fill. So the thing that got left is the data adapter.
Why isn't it created/instanitiated?
Please help... I'm stuck with this for the last 3 days I still can't figure
out the cause/solution for it.
Thank you very much.
Stanav.
 
S

S. Justin Gengo

Stanav,

I've had trouble with this also. I've learned to only use datareaders... I
loop through the data returned and create my own dataset when necessary to
have one. I.e. when returning the dataset via a webservice.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

Stanav

Thank you for the tip, Justin.
I'll try the datareader today and let you know the results.
Stanav.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top