VantiveGuy
Member
Hi,
I have a VB.Net (vs2005) application that connects to Sybase database and runs queries (and returns to grid, to XML and to Stye Sheet) but I am having a big problem trying to execute SQL that is written as a script, i.e contains a Begin and End statement, and creates and uses temp tables.
The script runs fine when executed in Sybase, but when I execute in VB.Net I find that the recordset is closed.
I am setting up the connection as :
connectstr = "Driver={SYBASE ASE ODBC Driver};Srvr='" & strServer & "';db='" & strDB & "';Uid='" & strUser & "';Pwd='" & strPass & "'"
Dim conn As Connection = New Connection
Dim connMode As Integer = ConnectModeEnum.adModeUnknown
conn.CommandTimeout = 300
and then executing the SQL to return into a recordset with :
Try
rs = conn.Execute(sQry)
Catch ex As Exception
MsgBox(ex.Message)
conn.Close()
Form2.Close()
Exit Sub
End Try
the conn.Execute runs, and I get no exception, but when I try to check for rs.EOF I get an error saying "Operation is not allowed when the object is closed."
I can't understand why it is saying that the object is closed. At the least, I should be able to test for BOF or EOF of the recordset! (It does return data when executed in Sybase)
Other queries work just fine using the same code, so I suspect that VB.Net has a problem with the SQL, which is copied below.
Basically, the query is used to find dependencies and works by searching syscomments (joining two lines to miss anything that bridges two lines).
I have to also say I claim no credit for the code.
It works when called as a stored procedure, but I can't create new stored procs on some environments so I want it to run as a script.
This is the script:
begin
declare @tabname2 varchar(72)
Select @tabname2 = 'MY_TABLE'
declare @tabname varchar(72)
set @tabname = '%' + @tabname2 + '%'
select com.id, com.text + isnull(com2.text,'') text
into #syscom
from syscomments com
left outer join syscomments com2
on com2.id = com.id
and com2.colid = com.colid + 1
select distinct '%' + object_name(com.id) + '%' Name, ob.type Type
into #tbvw
from #syscom com, sysobjects ob
where text like @tabname
and ob.id = com.id
and ob.type = 'V'
union
select @tabname, 'U'
Insert into #tbvw Select o.name , o.type from sysdepends d, sysobjects o where d.depid =
(select id from sysobjects where name = @tabname2)
and d.id = o.id
select distinct object_name(com.id) Name --, ob.type Type
from #syscom com, sysobjects ob, #tbvw
where com.text like #tbvw.Name
and ob.id = com.id
and ob.name <> @tabname2
Union Select swName Name from SW_BASIC_SCRIPT where swText like @tabname
Union Select RTRIM(n.swName)+"/ScreenEvent/"+e.swScreenName from SW_SCREEN_EVENT e, SW_EVENT_ENUM n Where e.swEventEnum = swEnum and swUserProgram like @tabname
Union Select RTRIM(n.swName)+"/"+RTRIM(e.swScreenName) +"/"+f.swColumnPath from SW_FIELD_EVENT e, SW_SCREEN_FIELD f, SW_EVENT_ENUM n
Where e.swScreenFieldId = f.swScreenFieldId and e.swEventEnum = n.swEnum and swUserProgram like @tabname
Union Select "Derived/"+swScreenName from SW_DERIVED where swStatement like @tabname
Order by Name
Drop table #syscom
Drop table #tbvw
end
Can anyone please tell me why VB.NET cannot handle this when executed as SQL?
Many thanks for any advice.
I have a VB.Net (vs2005) application that connects to Sybase database and runs queries (and returns to grid, to XML and to Stye Sheet) but I am having a big problem trying to execute SQL that is written as a script, i.e contains a Begin and End statement, and creates and uses temp tables.
The script runs fine when executed in Sybase, but when I execute in VB.Net I find that the recordset is closed.
I am setting up the connection as :
connectstr = "Driver={SYBASE ASE ODBC Driver};Srvr='" & strServer & "';db='" & strDB & "';Uid='" & strUser & "';Pwd='" & strPass & "'"
Dim conn As Connection = New Connection
Dim connMode As Integer = ConnectModeEnum.adModeUnknown
conn.CommandTimeout = 300
and then executing the SQL to return into a recordset with :
Try
rs = conn.Execute(sQry)
Catch ex As Exception
MsgBox(ex.Message)
conn.Close()
Form2.Close()
Exit Sub
End Try
the conn.Execute runs, and I get no exception, but when I try to check for rs.EOF I get an error saying "Operation is not allowed when the object is closed."
I can't understand why it is saying that the object is closed. At the least, I should be able to test for BOF or EOF of the recordset! (It does return data when executed in Sybase)
Other queries work just fine using the same code, so I suspect that VB.Net has a problem with the SQL, which is copied below.
Basically, the query is used to find dependencies and works by searching syscomments (joining two lines to miss anything that bridges two lines).
I have to also say I claim no credit for the code.
It works when called as a stored procedure, but I can't create new stored procs on some environments so I want it to run as a script.
This is the script:
begin
declare @tabname2 varchar(72)
Select @tabname2 = 'MY_TABLE'
declare @tabname varchar(72)
set @tabname = '%' + @tabname2 + '%'
select com.id, com.text + isnull(com2.text,'') text
into #syscom
from syscomments com
left outer join syscomments com2
on com2.id = com.id
and com2.colid = com.colid + 1
select distinct '%' + object_name(com.id) + '%' Name, ob.type Type
into #tbvw
from #syscom com, sysobjects ob
where text like @tabname
and ob.id = com.id
and ob.type = 'V'
union
select @tabname, 'U'
Insert into #tbvw Select o.name , o.type from sysdepends d, sysobjects o where d.depid =
(select id from sysobjects where name = @tabname2)
and d.id = o.id
select distinct object_name(com.id) Name --, ob.type Type
from #syscom com, sysobjects ob, #tbvw
where com.text like #tbvw.Name
and ob.id = com.id
and ob.name <> @tabname2
Union Select swName Name from SW_BASIC_SCRIPT where swText like @tabname
Union Select RTRIM(n.swName)+"/ScreenEvent/"+e.swScreenName from SW_SCREEN_EVENT e, SW_EVENT_ENUM n Where e.swEventEnum = swEnum and swUserProgram like @tabname
Union Select RTRIM(n.swName)+"/"+RTRIM(e.swScreenName) +"/"+f.swColumnPath from SW_FIELD_EVENT e, SW_SCREEN_FIELD f, SW_EVENT_ENUM n
Where e.swScreenFieldId = f.swScreenFieldId and e.swEventEnum = n.swEnum and swUserProgram like @tabname
Union Select "Derived/"+swScreenName from SW_DERIVED where swStatement like @tabname
Order by Name
Drop table #syscom
Drop table #tbvw
end
Can anyone please tell me why VB.NET cannot handle this when executed as SQL?
Many thanks for any advice.