Read AR System Database and export to TXT file via VBScript - vbscript

I have a BMC Remedy database with the AR System driver. I need to read this database, extract the information and save it in TXT.
I've searched in several places and found nothing. I tried to build something with what I was reading, but it is not working very well.
dim sql
dim connectionString
Dim bindingSource1
Dim myAdapter
Dim commandBuilder
connectionString="DRIVER={AR System ODBC Driver};ARServer=10.2.67.22;ARServerPort=1530;UID=xxxxx;PWD=xxxxx;ARAuthentication=;SERVER=NotTheServer"
sql="SELECT ""Controle_Crachá"".""Request ID FROM Controle_Crachá Controle_Crachá"
Me.SQLDS_reportresults.DataSource = bindingSource1
myAdapter= New OdbcDataAdapter(sql, connectionString)
commandBuilder= New OdbcCommandBuilder(myAdapter)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
myAdapter.Fill(table)
bindingSource1.DataSource = table
Me.SQLDS_reportresults.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)

Related

Unspecified error while executing sql query vba on Oracle database

I want to import data from Oracle database to Excel using VBA. I've tried several options I found in here or in the official manual but none of them seem to work for me - I always get the same unspecified runtime error on line with
rs.Open strSQL1, con
or
Set rs = con.Execute(strSQL1)
depending on which one of these two methods I use obviously. Here is the whole code:
Sub data_distribution()
'Setting up the database connection
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL1, strInput, strCon As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
strCon = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=XXX)(PORT=XXX))" & _
"(CONNECT_DATA=(SERVICE_NAME=XXX))); uid=XXX; pwd=XXX;"
'--- Open the above connection string.
con.ConnectionString = strCon
con.Open
'con.Open strCon
'--- Now connection is open and you can use queries to execute them.
'--- It will be open till you close the connection
'Definition of parameter
strInput = InputBox("Insert car_id")
strSQL1 = "select * from car where car_id = " & strInput & ""
'Executing the query
'rs.activeconnection = con
'rs.Open strSQL1, con
Set rs = con.Execute(strSQL1)
rs.Open strSQL1, con
Worksheets("Data").Range("A2").CopyFromRecordset rs
'Closing connection
rs.Close
con.Close
Set con = Nothing
Set rs = Nothing
I was thinking it might be an issue of connecting to the database but if I import/query data manual, it works just fine. For example using this manual
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
I had to download and configure ODAC for Windows from Oracle site to make it work. I use tsnames.ora to set the path. Wasn't sure if I configured it right but it works so I guess there isn't a problem with the connection in vba either, or is it? (The variables are, of course, set to real values, not "XXX")
The query itself is correct and returns valid results from the database. Libraries necessary to use ADOBD are linked as well. (Microsoft ActiveX Data Objects 2.0 Library)
There is an existing question with the same error but it's unresolved:
Unspecified run time error while executing vba script
I'm guessing it's station/interface specific (I use Excel 2010, SQL developer).
Even though it's been some time I asked the question, here, it's still unresolved so I will answer myself.
The problem was in the car table where one of the attributes was type CLOB (CHARACTER LARGE OBJECT) with lenght over 2000 characters. Excel was unable to cope with that type and the query caused the unspecified error. If I listed all attributes but this one, it all went well.

user defined type not defined in vb 6.0

I am trying to connect my vb 6.0 application to the database , so i have declared my data base as Dim dbStu as Database,but while compiling it is giving me error user defined type not defined , i found on another thread that , i need to add the Microsoft Active x Data Objects 2.8 for xp.I have done that too.so now my doubt is am i doing this correct ? should i have to declare those data base variable in form only ?.Or is there anything that is causing the error
you must add a reference to Microsoft Active x Data Objects 2.8 or later
then declare an ADODB.Connection and open it with proper ConnectionString value that specify your database path and if it has a password a password value
and then you can use this connection object to get data from your database or insert data to it
public cnn As ADODB.Connection
public rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "PROVIDER=MSDataShape;DATA PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= DatabasePath\DatabaseName.mdb ;Jet OLEDB:Database " 'Password= DataBasePassword ;"
Set rs = New ADODB.Recordset
rs.Open "Select * from FZONE ", cnn, adOpenDynamic, adLockOptimistic

WMI Scripting issues displaying multiple drive info

Please note that I am a newbie in WMI, have been researching this issue for most of the day, and even though there are hundres of posts, I am struglling to find any help on this specific problem.
Experiencing an issues using Win32_DiskDrive - Caption and also name functions:
When I execute the VB.script:
Try
Dim connection As New ConnectionOptions
connection.Username = userNameBox.Text
connection.Password = passwordBox.Text
connection.Authority = "ntlmdomain:ms1"
Dim scope As New ManagementScope( _
"\\ms1\root\CIMV2", connection)
scope.Connect()
Dim query As New ObjectQuery( _
"SELECT * FROM Win32_DiskDrive")
Dim searcher As New ManagementObjectSearcher(scope, query)
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_DiskDrive instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("Caption: {0}", queryObj("Caption"))
Next
it correctly lists the 5 harddrives that I have in the server i am querying.
But when I execute it in asp.net (vb) it lists only the 1 drive.
Dim query4 As New ObjectQuery("Select * from Win32_DiskDrive")
Dim searcher4 As New ManagementObjectSearcher(scope, query4)
For Each queryObj3 As ManagementObject In searcher4.Get()
'Availability
' text15.Text = queryObj3("Name")
text16.Text = queryObj3("Caption")
Next
My resuls are bountd to a textfield, formatted to wrap and multiline.
Regards
Louis van Rooyen
It seems you overrwrite text16.Text again and again, so the result in the end would be the information of the last device only.
Try concatenating the string instead:
' TODO: Use proper string formating instead of simpy string concatenating '
text16.Text = text16.Text & queryObj3("Caption")

need help in macros and access DB with external oracle DB connectivity?

In existing Microsoft Access DataBase we have table that inputvalue mapped from oracle DB,I hope with help of macros its getting purged into the access DB from Oracle DB. here my question is there is anyway to identify the existing mapping between oracle DB Field to Access DB Field? Please help on this.
Using VBA:
Dim fld As DAO.Field
Dim tdf As TableDef
Dim db As Database
Set db = CurrentDb
For Each tdf In db.TableDefs
''Linked table
If Len(tdf.Connect) > 0 Then
Debug.Print tdf.Connect
''Local name
Debug.Print tdf.Name
''Source name
Debug.Print tdf.SourceTableName
For Each fld In tdf.Fields
''Local name
Debug.Print fld.Name
''Source name
Debug.Print fld.SourceField
Next
End If
Next

VB6 Oracle Retrieving Clob into an array

I am trying to retrieve an oracle field with datatype clob into a VB array without reformating the retrieval SQL string (simply SELECT * FROM my_table). I am using an ADO recordset.
The clob values are lost when I close the connection or do any other action with the recordset. How can I achieve this.
In one of my projects I tried to manipulate BLOBs and CLOBs using ADO, but without any success, until I switched to Oracle Objects 4 OLE. You need to install and configure Oracle client on your machine, the in project references add "Oracle InProc Server 4.0 Type Library".
Here's a sample code I used for BLOBs:
Dim OraSession As OracleInProcServer.OraSessionClass
Dim OraDatabase As OracleInProcServer.OraDatabase
Dim OraDynaset As OracleInProcServer.OraDynaset
Dim srcImg As OraBlob
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.DbOpenDatabase("myDBName", "login/password", 0&)
Set OraDynaset = OraDatabase.DbCreateDynaset("SELECT src_id, src_image from Sources where src_file_name like '%.png'", 0&)
With OraDynaset
If .RecordCount > 0 Then
.MoveFirst
While (Not .EOF Or .BOF)
Set srcImg = .Fields("src_image").Value
srcImg.CopyToFile ("C:\sources\" & srcID & ".png")
.MoveNext
Wend
End If
End With
Set OraDynaset = Nothing
Set OraDatabase = Nothing
Set OraSession = Nothing

Resources