executereader fails on an odbc connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to access a sybase database via an odbc call. here is a snipit of cod
Imports System.Data.Odb

dim sql_statement="Select * from test_table
Dim con = New OdbcConnection("DSN=Sybase Has4win"
con.open(
Dim command As New OdbcComman
command.Connection = co
command.CommandType = CommandType.Tex
command.CommandText = sql_statemen
Dim reader As OdbcDataReade
reader = command.ExecuteReade
Do While reader.Read(
'populate datset with cal
Loo
reader.Close(
con.Close(

the app fails on
reader = command.ExecuteReader with no errors, just the generic we have encountered a problem blah blah bla

any ideas
thank
 
Mike:

Trap an ODBC exception with a try catch aroudn the executereader and see
what exception.ToString tells you. A couple of things could be the problem
but if you can open the connection, if you are getting that far, then it's
probably a syntax error/invalid object name or a permission issue. It's
hard to tell from here but if the Connection opens then your DSN is ok and
the .dll apparently works.

Let me know what it says..Also, I noticed the comment says something about a
DataSet. That may be just a syntactical thing, but if you are populating a
DataSet, it's probably a lot easier using a DataAdapter. True that an
Adapter uses a reader behind the scenes to fill a DataSet, but you are going
to have to do some extra work and the solution will be alittle more
convoluted....

dim sql_statement="Select * from test_table"
Dim con = New OdbcConnection("DSN=Sybase Has4win")
Dim command As New OdbcCommand(sql_statement, con)
command.CommandType = CommandType.Text

Try
con.open()
Catch ex as ODBCException
Debug.Assert(false, ex.ToString())
End Try
Dim reader As OdbcDataReader
Try
reader = command.ExecuteReader
Catch ex as ODBCException
Debug.Assert(false, ex.ToString())
End Try
Do While reader.Read()
'populate datset with call
Loop
reader.Close()
con.Close()

HTH,

Bill
mike deck said:
I am trying to access a sybase database via an odbc call. here is a snipit of code
Imports System.Data.Odbc



the app fails on
reader = command.ExecuteReader with no errors, just the generic we have
encountered a problem blah blah blah
 
Back
Top