Wednesday, April 16, 2008

Access database without DSN

Developers used to write the code to retrieve the data from database, with the help of DSN (Data Source Name). Developers does not bother about the type of database. DSN is the bridge between database and scripting language.

Assume that your automation scripts are using a DSN. It is difficult to configure DSN, whenever the script runs. But you can set the DSN details dynamically to connect with any database. Below I have given the sample silktest (4test) code to run the script without having physical DSN.

4test code:

[+] void GetAccessDB ()
[ ] STRING CONN_STRING = "Driver=" + Chr(123) + "Microsoft Access Driver (*.mdb)" + Chr(125) + ";Dbq=\\AppServer\build05.mdb;Mode=16;"
[ ] HANDLE dbConn
[ ]
[ ] dbConn = DB_Connect(CONN_STRING)
[ ] hSQL=DB_ExecuteSql(dbConn, "Select * from Emp_Master")
[ ]
[ ] DB_FinishSql (hSQL)
[ ] DB_Disconnect (dbConn)

No comments: