Infobright database connection through vb script - vbscript

Can anyone tell me how to connect infobright database through vb script. I have written a code but it shows an error:
provider can not be found.
The code I have written is:
Option Explicit
Dim conn, sqlstr
sqlstr = "SELECT COLLATION_NAME FROM COLLATIONS"
'Database connection info
set Conn = CreateObject("ADODB.connection")
Conn.ConnectionTimeout = 30
Conn.CommandTimeout = 30
conn.open("Provider=Microsoft.Jet.OLEDB.4.0;Database=information_Schema;Username=root;Password=''")
dim showList
Set showList = conn.execute(sqlstr)
while not showList.eof
Wscript.echo "Collation Name:" & showList("COLLATION_NAME")
showList.MoveNext
WEND
conn.close

Install MySQL Connector/ODBC 5.1 and use a connection string like the following
connString = "Driver={MySQL ODBC 5.1 Driver};Server=ServerAddress;Database=DataBase;User=Username; Password=Password;"

Related

QTP connection string for Sybase 16 database?

I can't seem to get my connection string correct.
Dim conn, rs
Set conn= createobject("adodb.connection")
set rs = createobject("adodb.recordset")
conn.Open "Provider=Sybase.ASEOLEDBProvider;Server Name = xxx.xxx.xxx.xxx,yyyy;User Id=user;Password=pwd;Database=mydatabase;"
rs.open "Select * from blah", conn
I keep getting an error stating, "Provider cannot be found. It may not be properly installed."
I know the provider is installed because I use the same computer for coding up C# applications that connect to Sybase 16 successfully all the time. Does anyone know the correct connection string for QTP/UFT?
I figured it out.
Dim conn, rs
Set conn= createobject("adodb.connection")
set rs = createobject("adodb.recordset")
conn.Open "Driver={Adaptive Server Enterprise}; Server=xxx.xxx.xxx.xxx; port=yyyy; uid=user; pwd=pwd; db=mydatabase;"
rs.open "Select * from blah", conn
Using this you'll be able to use QTP/UFT and connect to a sybase 16 database - so long as you have have the Sybase Adaptive Server Enterprise drivers installed on your system. It's a proprietary database and to my knowledge you'll have to either purchase drivers directly from Sybase or from a thrid party. If you're running Sybase 16 at your company you more than likely have the ASE drivers - ask around.
There is way to connect if it is in windows 7 Function
ConnectionTest()
DB_CONNECT_STRING = "Provider=OraOLEDB.Oracle; Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" & myHostName & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & myServiceNameOrSID & "))); User ID=" & myUsername & ";Password=" & myPassword & ";"
Set myConn = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
myConn.Open DB_CONNECT_STRING
objRecordSet.Open myQuery, myConn
Wscript.Echo objRecordSet.fields.item(1) & " " & objRecordSet.fields.item(2)
myConn.Close
End function
Call ConnectionTest()
if there is problem in mapping adodb driver need to invoke the exe file before running in windows 64 bit

Excel is being closed while connecting to Oracle using VBA

I am trying to connect to Oracle using Excel VBA but when the code is run, Excel is closed and reopened at line MsgBox rs.recordCount
Sub Ora_Connection()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim query As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
On Error GoTo final1
query = "Select * from EMP where EMP_NO='998234'"
strcon = "Driver={Oracle in OraClient11g_home1};Dbq=smqa;Uid=MyUserID;Pwd=MyPassword;"
con.Open (strcon)
rs.CursorType = 1
rs.Open query, con
rs.MoveLast
MsgBox rs.recordCount
rs.Close
Set s = Nothing
con.Close
Set con = Nothing
final1:
MsgBox err.Number & " " & err.Description
End Sub
I am running this code on Windows 7 and trying to connect Oracle 11g. Do I need any additional setup to connect Oracle Db using Excel VBA or is something wrong in the code?

How to connect a database to crystal report at run time?

I am developing winform application in vb6. I am using crystal report 4.6. I have created a crystal report which shows all data from a table (MS Access). And I unchecked save data with report and i saved the report. I just want to invoke it in application. So I included the component CrystalReportControl in my application. Now i want to set the records to be displayed in the report. The records are selected according to the user input to the text box.
Records are retrived from the database is done in following code.
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Set conn = New ADODB.Connection
conn.Open "provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path &"\faculty.mdb"
Set rs = New ADODB.Recordset
rs.Open "select * from facultydetails where eid=1234", conn, adOpenDynamic, adLockPessimistic
CrystalReport1.ReportFileName = App.Path & "\faculty.rpt"
Set CrystalReport1.DataSource = rs
CrystalReport1.Action = 1
End Sub
Gives an error for the line: Set CrystalReport1.DataSource = rs :
as Property is write-only.
Tell me how the records of the report can be dynamic? Plz help me...
Instead of
Set CrystalReport1.DataSource = rs
do
CrystalReport1.DataSource = rs
EDIT:
Take a look at the following example and see if that will help you:
'CrystalReport1 is the name of the dsr file
Dim Report As New CrystalReport1
Dim cdoRowset As CrystalDataObject.CrystalComObject
Dim varArray() As Variant
'Open ADO Connection
Set m_cnAdo = New ADODB.Connection
m_cnAdo.ConnectionString = "DRIVER={SQL Server};UID=[UserID];PWD=[Password]" _
& ";SERVER=[Server];DATABASE=[Database]"
m_cnAdo.Open
Dim rsAdo As ADODB.Recordset
Dim cmdAdo As ADODB.Command
'Using Embedded Query
Set cmdAdo = New ADODB.Command
Set rsAdo = New ADODB.Recordset
cmdAdo.ActiveConnection = m_cnAdo
cmdAdo.CommandText = "SELECT * FROM Table WHERE Param = " & lngParam1
cmdAdo.CommandType = adCmdText
Set rsAdo = cmdAdo.Execute
Report.Database.SetDataSource rsAdo, 3, 1

ADO "Unspecified Error" instead of actual error when fetching server side cursor

This relates to my recent question: Force Oracle error on fetch
I am now able to reproduce a scenario where using ADO with the Oracle OLEDB Provider, I can force an error such as ORA-01722: invalid number to occur on calling Recordset.MoveNext However, this is not the error that is returned to the application. Instead, the application sees Provider error '80004005' Unspecified error. How can I get the application to see the real error from the database? This is with Oracle 10g (client and server), if it matters.
Sample code is roughly as follows:
Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
con.ConnectionString = "Provider=OraOLEDB.ORACLE;Data Source=xxx;User Id=yyy;Password=zzz"
con.CursorLocation = adUseServer
con.Open
Set cmd.ActiveConnection = con
cmd.CommandText = "select * from table(ret_err)"
cmd.Prepared = True
Set rs = cmd.Execute
While Not rs.EOF
rs.MoveNext
Wend
SQLCODE and SQLERRM should be returned with an SQL call.
It looks like ADO Error is the interface for accessing this.

VB6 and ODBC commands

I started a thread here, this is a continuation from that post: Calling a Module and a Class within a Form
I can't find the information I need to successfully query our database. What I need to do is to get a single value from a Pervasive database. I cannot find the list of ODBC commands to do this with.
Can someone please point me to some documentation that deals with these Pervasive ODBC commands? I'm using ADO ODBC for the connection.
EDIT:
I am also attempt to connect to a MySQL database as well and am hitting the same error. Here is a test Sub I created to call my MySQL function. The error is the same for MySQL as it is for Pervasive: "Object variable or With Block variable not set"
Public Sub testMe(id)
Dim MySqlConn As adodb.Connection 'Do I need this here or in the MySQL function?
Set MySqlConn = ConnectMySQL()
MySqlConn.Open "SELECT * FROM test", MySqlConn, adOpenDynamic, adLockOptimistic
End Function
First, you need to connect to the database. According to this website the connection string would be in this format:
Driver={Pervasive ODBC Client
Interface};ServerName=myServerAddress;dbq=#dbname;
Starting with code from your previous post, it could be extended like this:
Option Explicit
Public Function getEmployee() As String
Dim MyConnection As ADODB.Connection
Dim CM As ADODB.Command
Dim RS As ADODB.Recordset
Set MyConnection = ConnectSQL()
'one way using command objects
Set CM = New ADODB.Command
Set CM.ActiveConnection = MyConnection
CM.CommandType = adCmdText
CM.CommandText = "select * from <table>"
Set RS = New ADODB.Recordset
RS.Open CM, , adOpenStatic, adLockBatchOptimistic
'another way using just the connection
Set RS = MyConnection.Execute("select * from <table>")
'return the data
getEmployee = RS.Fields(0).Value
End Function
Public Function ConnectSQL() As ADODB.Connection
Set ConnectSQL = New ADODB.Connection
ConnectSQL.Open "Driver={MySQL ODBC Client Interface};ServerName=localhost;dbq=#testdb"
End Function

Resources