Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

odbc call to sql 5.5 from visual basic.net

2 posts in General Discussion Last posting was on 2004-04-21 13:24:42.0Z
mike deck Posted on 2004-04-19 20:39:55.0Z
Sender: 3ce9.4084375c.1804289383@sybase.com
From: mike deck
Newsgroups: ianywhere.public.general
Subject: odbc call to sql 5.5 from visual basic.net
X-Mailer: WebNews to Mail Gateway v1.1s
Message-ID: <40843916.3d05.846930886@sybase.com>
X-Original-NNTP-Posting-Host: 10.22.241.42
X-Original-Trace: 19 Apr 2004 13:39:50 -0700, 10.22.241.42
Lines: 39
X-Original-NNTP-Posting-Host: forums-2-dub.sybase.com
X-Original-Trace: 19 Apr 2004 13:39:52 -0700, forums-2-dub.sybase.com
NNTP-Posting-Host: forums-master.sybase.com
X-Original-NNTP-Posting-Host: forums-master.sybase.com
Date: 19 Apr 2004 13:39:55 -0700
X-Trace: forums-1-dub 1082407195 10.22.108.75 (19 Apr 2004 13:39:55 -0700)
X-Original-Trace: 19 Apr 2004 13:39:55 -0700, forums-master.sybase.com
X-Authenticated-User: ngsysop
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:2973
Article PK: 6442

I am working on an app that calls a databse via ODBC to
version 5.5.05 Build #2817 in visual basic .net. I am
opening a connection, but when passing a sql string I get an
unhandled win 32 exception on the executereader statement.
Here is the snipit of code

patient_id is a variable passed into the routine

'now populate with call to synergy dns database via odbc
Dim con = New OdbcConnection("DSN=Sybase*******")
con.open()
Dim command As New OdbcCommand
command.Connection = con
command.CommandType = CommandType.Text
' command.CommandText = "Select * from test_table
where patientcode='" + patient_id + "'"
Dim reader As OdbcDataReader
command.ExecuteReader()
Try
Catch ex As Exception
reader = command.ExecuteReader
MsgBox(ex.ToString)
End Try


Do While reader.Read()
'populate datset with call
Loop
reader.Close()
con.Close()

First in theory this should work, but it is not? The DSN
name is properly configured as I can import data into access
with that call, Has anyone made an odbc connection to sql
anywhere 5.5 from vb.net using just the DNS name? All I
need to do is bring some data into a dataset.

thanks
Mike


Chris Keating (iAnywhere Solutions) Posted on 2004-04-21 13:24:42.0Z
From: "Chris Keating \(iAnywhere Solutions\)" <FightSpam_keating@iAnywhere.com>
Newsgroups: ianywhere.public.general
References: <40843916.3d05.846930886@sybase.com>
Subject: Re: odbc call to sql 5.5 from visual basic.net
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
X-Original-NNTP-Posting-Host: keating-xp.sybase.com
Message-ID: <40867616$1@forums-2-dub>
X-Original-Trace: 21 Apr 2004 06:24:38 -0700, keating-xp.sybase.com
X-Original-NNTP-Posting-Host: forums-2-dub.sybase.com
X-Original-Trace: 21 Apr 2004 06:24:39 -0700, forums-2-dub.sybase.com
NNTP-Posting-Host: forums-master.sybase.com
X-Original-NNTP-Posting-Host: forums-master.sybase.com
Date: 21 Apr 2004 06:24:42 -0700
X-Trace: forums-1-dub 1082553882 10.22.108.75 (21 Apr 2004 06:24:42 -0700)
X-Original-Trace: 21 Apr 2004 06:24:42 -0700, forums-master.sybase.com
X-Authenticated-User: ngsysop
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:2982
Article PK: 6449

There are several coding issues with this code:

1) The following code does not assign the command results to the reader.

Dim reader As OdbcDataReader
command.ExecuteReader()

2) You Catch logic assigns the command results to the reader but by that
point, the exception has occurred


The following works againts the SADEMO Database:

Dim con = New OdbcConnection("DSN=SQL Anywhere 5.0 Sample")
con.open()
Dim command As New OdbcCommand
command.Connection = con
command.CommandType = CommandType.Text
command.CommandText = "Select * from department"
Dim reader As OdbcDataReader
'command.ExecuteReader()
Try
reader = command.ExecuteReader()

Catch ex As Exception
MsgBox(ex.ToString)
End Try


Do While reader.Read()
'populate datset with call
Loop
reader.Close()
con.Close()


--

Chris Keating
Sybase Adaptive Server Anywhere Professional Version 8

****************************************************************************
*
Sign up today for your copy of the SQL Anywhere Studio 9 Developer Edition
and try out the market-leading database for mobile, embedded and small to
medium sized business environments for free!

http://www.ianywhere.com/promos/deved/index.html

****************************************************************************
*

iAnywhere Solutions http://www.iAnywhere.com

** Please only post to the newsgroup

** Whitepapers can be found at http://www.iAnywhere.com/developer
** EBFs can be found at http://downloads.sybase.com/swx/sdmain.stm
** Use CaseXpress to report bugs http://casexpress.sybase.com

****************************************************************************
*

<mike deck> wrote in message news:40843916.3d05.846930886@sybase.com...
> I am working on an app that calls a databse via ODBC to
> version 5.5.05 Build #2817 in visual basic .net. I am
> opening a connection, but when passing a sql string I get an
> unhandled win 32 exception on the executereader statement.
> Here is the snipit of code
>
> patient_id is a variable passed into the routine
>
> 'now populate with call to synergy dns database via odbc
> Dim con = New OdbcConnection("DSN=Sybase*******")
> con.open()
> Dim command As New OdbcCommand
> command.Connection = con
> command.CommandType = CommandType.Text
> ' command.CommandText = "Select * from test_table
> where patientcode='" + patient_id + "'"
> Dim reader As OdbcDataReader
> command.ExecuteReader()
> Try
> Catch ex As Exception
> reader = command.ExecuteReader
> MsgBox(ex.ToString)
> End Try
>
>
> Do While reader.Read()
> 'populate datset with call
> Loop
> reader.Close()
> con.Close()
>
> First in theory this should work, but it is not? The DSN
> name is properly configured as I can import data into access
> with that call, Has anyone made an odbc connection to sql
> anywhere 5.5 from vb.net using just the DNS name? All I
> need to do is bring some data into a dataset.
>
> thanks
> Mike