Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connection string issue with MS access
#1
Solved: 11 Years, 4 Months, 1 Week ago
Hi ,
I have created a database in MSaccess(.mdb).while i connecting in the qtp .Its giving error

My issue is i want to conenct to db and retrive one table and its value in the external excel sheet or datatable

my code :
Code:
set a=createobject('Odbc.connection")
a.open provider="my connection string"
set b =createobject('Odbc.recordset")
b.open "select * from employees",a

while runing its stopping at second line .i think my connection string is wrong .hw can i get the correct connection string for .mdb file.

pls help
Reply
#2
Solved: 11 Years, 4 Months, 1 Week ago
go to ConnectionStrings.com
Reply
#3
Solved: 11 Years, 4 Months, 1 Week ago
you should create a object for "adodb.connection" not "Odbc.connection"
anyways following code should solve your problem..

Code:
Set conn = CreateObject("adodb.connection")
Set rec = CreateObject("adodb.recordset")

conn.Provider = "microsoft.jet.oledb.4.0"
conn.Open "specify path of your access database file here"

rec.Open "specify your query here", conn
Reply
#4
Solved: 11 Years, 4 Months, 1 Week ago
Hi pavan

I followed this code

Code:
Set con = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")

con.open "Provider=my query string"
rs.open "sql query ",con
i=0
do until rs<>eof
dim arr
arr(i)=rs("Columnname").value

i=i+1

rs.movenext

loop
.

my scenario is i want to connect database and from one table 's column 's value fetch and save in excel sheet or datatable.

ex.form employee table i want to fetch First name column's values in excel r datatable.

pls help
Reply
#5
Solved: 11 Years, 4 Months, 1 Week ago
pls help on this issue


Thanks in advance
Reply
#6
Solved: 11 Years, 4 Months, 1 Week ago
Hi Madhu,

Check out the below example & implement accordingly.

Note: Create a Datasource("flight32.dsn") in C:\Program Files\Common Files\ODBC\Data Sources( which is assigned to FILEDSN variable in below code)

Code:
Dim db
Set db=CreateObject("ADODB.Connection")
db.connectionString="DBQ=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app\flight32.mdb;DefaultDir=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\flight32.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
db.Open
Set RecordSet=db.Execute("Select * from Orders")
i=1
While (NOT recordset.EOF)
      Datatable.SetCurrentRow(i)
       Datatable("CustomerName",dtGlobalSheet)=Recordset.Fields("Customer_Name")
        msgbox Datatable("CustomerName",dtGlobalSheet)
       Recordset.MoveNext
       i=i+1
Wend
db.Close
Set db=Nothing


Once test run is finished,check in RunTime Datatable of Test Results, entire Backend Table's data under "Customer_Name" column will imported to QTP Datatable's Column "CustomerName"

Hope this would solve your issue.Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [UFT] Connection String for Oracle robertosalemi 6 12,305 01-15-2016, 04:51 PM
Last Post: robertosalemi
  DB2 Connect connection with IE 11 SRP 1 2,623 12-18-2015, 12:41 PM
Last Post: vinod123
  IBM DB2 connection with VB script bmurali 2 10,922 12-18-2015, 12:38 PM
Last Post: vinod123
  Connection with HP ALM hachem 0 2,630 02-26-2015, 04:36 PM
Last Post: hachem
  “Cannot connect to 8822 (connection timed out)" Ikbal 0 2,143 12-08-2014, 11:38 PM
Last Post: Ikbal

Forum Jump:


Users browsing this thread: 1 Guest(s)