Oracle VBAscript connection error - oracle

Dim strDBDesc As String
strDBDesc = "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = ##)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ##)))"
cn.Open "Provider=OraOLEDB.Oracle;Data Source=" & strDBDesc & ";User ID=##;Password=##;"
query1 = ""
query1 = ERM.Sheets("query").Range("A10")
query1 = Replace(query1, "v_job_name", v_field1)
'Set OraDynaSet = objdatabase.DBCreateDynaset(query1, 0&)
Dim OraDynaSet As ADODB.Recordset
Set OraDynaSet = CreateObject("ADODB.Recordset")
OraDynaSet.ActiveConnection = cn
OraDynaSet.Open query1, cn, adOpenStatic
I am getting error message as ORA-00933 sql command not ended properly
Error Message
Query 1
select
job_name,Status
from (
select Distinct a.job_name,
a.description description,Decode (job_type,98,'Box',99,'Command Job',102,'File watcher job',job_type) job_type,
substr(decode(d.status,1,'Running',
3,'Starting',
4,'Success',
5,'Failed',
6,'Terminated',
7,'On Ice',
8,'Inactive',
9,'Activated',
11,'On Hold',
12,'Que Wait',
d.status),1,9) status,
a.mach_name,a.owner,g.command,g.std_err_file,g.std_out_file,f.days_of_week,f.start_times,f.start_mins,f.run_calendar,f.max_run_alarm,profile
from AEDBADMIN.ujo_job a,
AEDBADMIN.ujo_job_runs c,
AEDBADMIN.ujo_job_status d,
(select joid,max(STARTIME) startime,
max(endtime) endtime
from AEDBADMIN.ujo_job_runs group by joid) e,
AEDBADMIN.ujo_command_job g,
AEDBADMIN.ujo_sched_info f
where a.joid = c.joid(+)
and a.joid = d.joid(+)
and a.joid = e.joid(+)
and a.joid = f.joid(+)
and a.joid = g.joid(+)
and (c.startime = e.startime or c.startime is null)
and job_name ='v_job_name'// job name replaces
and a.is_active =1
);

I think the problem is this one
and job_name ='v_job_name'// job name replaces
In SQL comments are done by -- ... (single line) or /* ... */ (multi line).
However, perhaps ADODB does not support comments at all, I recommend to remove it entirely.
Or it is the semicolon ; at the end - remove it.
Just a note, you should rewrite your query and use ANSI join syntax instead of old Oracle join syntax - especially for OUTER JOINS.

Related

How to use DataReader from Oledb and get results in Richtextbox

Dim srch As String
srch = ccode.Text
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + IO.Directory.GetCurrentDirectory + "\ptdr.accdb"
cmd.Connection = conn
conn.Open()
Dim dsrch As New OleDbCommand("SELECT pname, page, vdate, psex, summer, bldp, blds, photh, diag, rl, trtmnt, nvdate FROM ptnt_data WHERE pcode = " & srch & "", conn)
Dim rdr As OleDbDataReader = dsrch.ExecuteReader()
Dim dg As String = ""
'diagnosis'
dg = rdr.GetString(8).ToString()
If String.IsNullOrEmpty(dg) Then
diag1.Text = ""
ElseIf String.IsNullOrWhiteSpace(dg) Then
diag1.Text = ""
Else
diag1.Text = dg
End If
It works fine but when I search for a null it gives an error.
It says that I've an error at the line of
dg = rdr.GetString(8).Tostring()
any suggests?
rdr.GetString(8).ToString()
if rdr.GetString(8) is null this is a classic null reference exception
rdr.GetString(8) IS a string so just remove the .ToString()
As per my comment below you can only run GetString if the DB has an underlying type of string for this data, what is the datatype of column diag?
(ie run rdr.GetFieldType(8) in the debugger and provide the type name)
As you have confirmed this is a string type and the issue is just with null handling (sorry i didn;t spot that from your question) you need:
If rdr.IsDBNull(8) Then diag1.Text = "" Else diag1.Text = rdr.GetString(8) EndIf
Which should replace everything from Dim dg... down

types mismatch in VBScript

I am trying to get number of table's rows in db and output it to console using VBScript, but when I execute following code I get type mismatch error, what should I change in my code to force it execute without errors
Dim loop_lim
Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=BUG\SQLSERVER2005;Initial Catalog=test;user id ='sa';password='111111'"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command" )
myConn.Open DB_CONNECT_STRING
Set myCommand.ActiveConnection = myConn
myCommand.CommandText = "select count(*) from oferty o inner join rep_oferta ro on o.indeks = ro.srcdoc inner join rep_pozycje rp on o.indeks = rp.srcdoc"
loop_lim = myCommand.Execute
WScript.Echo loop_lim
Change
loop_lim = myCommand.Execute
to
Set loop_lim = myCommand.Execute
because .Execute returns a recordset object. Then think about how to get values from the recordset rsp. it's fields.

How to add "select all" to combo in vb6?

I wrote this function for selecting all values at option "select all"
Private Function Not_Null()
If CmbGrade.Text = "SELECT ALL" Then
sql = "SELECT A.ROLLNO,A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.ADDRESS,A.GRADE,B.DIV,A.BLOOD_GROUP,C.HOUSE,A.DATE_OF_BIRTH,A.TRANSPORT,A.SNAME,A.MEAL,A.RUTNO FROM STUDENT_RECORD_DATABASE A,DIVISION B,HNM C WHERE A.DIVID=B.DIVID AND A.HID=C.HID AND GRADE IS NOT NULL"
SET rs = cn.Execute(sql)
End If
End Function
After I called this function at command click
Private Sub CmdReport_Click()
Dim STRp As String
STRp = Not_Null()
sql = "SELECT A.ROLLNO,A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.ADDRESS,A.GRADE,B.DIV,A.BLOOD_GROUP,C.HOUSE,A.DATE_OF_BIRTH,A.TRANSPORT,A.SNAME,A.MEAL,A.RUTNO FROM STUDENT_RECORD_DATABASE A,DIVISION B,HNM C WHERE A.DIVID=B.DIVID AND A.HID=C.HID"
Set rs = cn.Execute(sql)
Set DataReport2.DataSource = rs
DataReport2.Show
End Sub
When I choose "select all" option it doesn't show any record
Please help..........
It doesn't matter that you're executing STRp = Not_Null(), because (a) Not_Null doesn't return a value and (b) even though you're doing a SET rs in Not_Null, then even assuming you've declared rs somewhere in your module or form, you're just overwriting its value in CmdReport_Click.
Try this:
Private Sub CmdReport_Click()
sql = "SELECT A.ROLLNO,A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.ADDRESS,A.GRADE,B.DIV,A.BLOOD_GROUP,C.HOUSE,A.DATE_OF_BIRTH,A.TRANSPORT,A.SNAME,A.MEAL,A.RUTNO FROM STUDENT_RECORD_DATABASE A,DIVISION B,HNM C WHERE A.DIVID=B.DIVID AND A.HID=C.HID AND GRADE ='" & CmbGrade.Text & "'"
If CmbGrade.Text = "SELECT ALL" Then
sql = "SELECT A.ROLLNO,A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.ADDRESS,A.GRADE,B.DIV,A.BLOOD_GROUP,C.HOUSE,A.DATE_OF_BIRTH,A.TRANSPORT,A.SNAME,A.MEAL,A.RUTNO FROM STUDENT_RECORD_DATABASE A,DIVISION B,HNM C WHERE A.DIVID=B.DIVID AND A.HID=C.HID AND GRADE IS NOT NULL"
End If
Set rs = cn.Execute(sql)
Set DataReport2.DataSource = rs
DataReport2.Show
End Sub
Also, it's obvious that you're lacking even the most basic understanding of your programming language (VB). I highly suggest picking up an introductory book on the subject, or searching for an online introductory tutorial before you go any further.

How to access specific date format?

<code>
Private Sub CmbRNO_Click()
sql = "SELECT
A.ROLLNO,A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.CONTACT,A.CONTACT1,A.CONTACT2,A.ADDRESS,A.GRADE,B.DIV,A.BLOOD_GROUP,C.HOUSE,A.DATE_OF_BIRTH,A.TRANSPORT,A.SNAME,A.MEAL,A.BUSNO,A.RUTNO,D.DNAME,D.DCONT,E.ANM,D.DADD,A.CARD_TYPE,A.CARD_NO
FROM
STUDENT_RECORD_DATABASE A,DIVISION B,HNM C,DRIVER D,ATTEND E
WHERE
A.DIVID=B.DIVID AND A.HID=C.HID AND A.DID=D.DID AND A.AID=E.AID AND ROLLNO ='" & CmbRNO.Text & "'"
Set RES = CON.Execute(sql)
TxtFNM.Text = RES!FIRST_NAME
TxtMIDNM.Text = RES!MIDDLE_NAME
TxtLNM.Text = RES!LAST_NAME
Text5.Text = RES!CONTACT
Text6.Text = RES!CONTACT1
Text7.Text = RES!CONTACT2
TxtADDR.Text = RES!ADDRESS
COMBO1.Text = RES!GRADE
CmbDIV.Text = RES!DIV
CmbBG.Text = RES!BLOOD_GROUP
CmbHOUSE.Text = RES!HOUSE
DTPicker1.Value = RES!DATE_OF_BIRTH //error showing
Combo10.Text = RES!TRANSPORT
CmbSTOP.Text = RES!SNAME
Combo11.Text = RES!MEAL
CmbBUS.Text = RES!BUSNO
Combo12.Text = RES!RUTNO
CmbDRIVER.Text = RES!DNAME
TxtDCONT.Text = RES!DCONT
CmbATTEND.Text = RES!ANM
Text10.Text = RES!DADD
Combo13.Text = RES!CARD_TYPE
Text11.Text = RES!CARD_NO
End If
End Sub
</code>
This is the full code to display student records on combo click
but error is: Invalid property value date_of_birth
Please help
This can be a result of difference in date format between oracle and vb6. To avoid that, I would explicitly define the date format while selecting the columns like this
SELECT
A.ROLLNO,
A.FIRST_NAME,
A.MIDDLE_NAME,
...
TO_CHAR(A.DATE_OF_BIRTH,'DD-MON-YYYY') DATE_OF_BIRTH
...
Then read it in VB6 by converting it into date:
DTPicker1.Value = CDate(RES!DATE_OF_BIRTH)

Parameterized query in Classic Asp

My db access code is like following:
set recordset = Server.CReateObject("ADODB.Recordset")
set cmd1 = Server.CreateObject("ADODB.Command")
cmd1.ActiveConnection = Conn //connection object already created
cmd1.CommandText = "SELECT * FROM lbr_catmaster where catname = ?"
cmd1.CommandType = adCmdText
set prm = cmd1.CreateParameter("#prm", 200, 1,200 , "development")
cmd1.Parameters.Append prm
set recordset = cmd1.Execute
But there is no db hit going. Please help with this. I am using sql server 2005.
Thanks.
In my code, this is how I get a recordset from a command:
Set rs = server.createobject("ADODB.Recordset")
Set cmd = server.createobject("ADODB.Command")
cmd.ActiveConnection = Conn //connection object already created
cmd.CommandText = "SELECT * FROM lbr_catmaster where catname = ?"
cmd.CommandType = adCmdText
cmd.CommandTimeout = 900
set prm = cmd.CreateParameter("#prm", 200, 1, 200, "development")
cmd.Parameters.Append prm
' Execute the query for readonly
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
Hope it helps
I like using Parameters.Refresh, i.e.
set recordset = Server.CReateObject("ADODB.Recordset")
set cmd1 = Server.CreateObject("ADODB.Command")
cmd1.ActiveConnection = Conn ' connection object already created
cmd1.CommandText = "SELECT * FROM lbr_catmaster where catname = ?"
cmd1.CommandType = adCmdText
cmd1.Prepared = True ' only needed if u plan to reuse this command often
cmd1.Parameters.Refresh
cmd1.Parameters(0).Value = "development"
set recordset = cmd1.Execute
Looks like you aren't referencing your named parameter correctly in your query.
Try replacing:
cmd1.CommandText = "SELECT * FROM lbr_catmaster where catname = ?"
with:
cmd1.CommandText = "SELECT * FROM lbr_catmaster where catname = #prm"
and see if that helps.
If you have a complex criteria using parameters here is an example I had to create based on my requirements
declare #loc smallint = ? , #dt1 date = ? SET #loc = ISNULL(#loc, 999)
SELECT m.* , c.*
FROM Costs c INNER JOIN MbrData m ON c.SN = m.SN and c.startDT = m.startDT
WHERE (m.LocationID = #loc OR #loc = 999) AND (MonthYear = #dt1 OR #dt1 IS NULL)
ORDER BY m.LocationID
then in your asp
cmd.CommandText = strSQL ' the string above
cmd.CommandType = 1 ' adCmdText
cmd.Parameters.Append cmd.CreateParameter("#loc",2,1) 'adSmallInt=2, adParamInput=1
cmd.Parameters("#loc") = rptlocation ' scrubbed location ID
cmd.Parameters.Append cmd.CreateParameter("#dt1",7,1) 'adDate=7, adParamInput=1
cmd.Parameters("#dt1") = scrubbed formatted date
set rst = cmd.Execute
Try leaving off the parameter name:
set prm = cmd1.CreateParameter(, 200, 1,200 , "development")

Resources